Correct prefix search logic