Added controller tests for search feature and refactored slightly