Fix for wraparound search (issue 6850)