completed refactoring of search