Little refactoring, move Dijkstra's algorithm to helper