refactored search stuff