refactor search method