finished search refactoring