refactor: put Search code into a helper method