made a small but important fix to the algorithm on the edge case that 2 nodes have the same position