updated search algorithm