Fixed connectVertices method by avoiding the same nodes.