Refactored search process