Improved search algorithm