Refactored and made a search method