Fully functioning dijkstra