Refactored search functionality for readability.