REFACTORED code in searchCtrl