Refactored search code into a module of its own