Fix bug in shortest path