refactored the search