Improved search algorithm.