Enhanced the search logic