Better search algorithm