Dijkstra shortest path refactoring