changed the structure of path search algorithm

functionality is the same