refactoring for search