Refactor search method