cleaner code for search functionality