Reimplemented dijkstra