Refactoring of search functionality