Fix search algorithm