Refactored the search functionality and added validators