Fixed the shortest path algorithm