Adding test plus correcting some logic for the search