search refactoring and unittesting