Refactored search functional.