finished search with clean code