refactored search a little