added function to find the shortest path