Updated search algorithm