added search unit tests and refactored code