Fix bugs in shortestPath