refactor of search functionality