improved search algorithm