minor modification + Dijkstra