Refactor search method.