Refactored code for adv. search result