modify Dijkstra method and add comments