refactored code in SearchActivity