Dijkstra prototype has an infinite loop