YJ- updated the search algorithm