Refactor search business logic.