better search algorithm