Refactoring and adding pending_search.