We should refactor the two middleware methods, which right now resides in util.js, to middlewares folder. Also, we need to refactor the common code between the two methods, right now we have to make changes in both methods, if have to add a new possible type for reference field.