refactored search logic to its own method ref #2 #3