A bit more refinement of the search logic.