refine search algorithm