refactor the search