Refactor Dijkstra design