             var toRemove: [Int] = [Int]()
             for l in 0..<edges[j].count {
                 if edges[j][l].v == index {
-                    //if there are indices already in the toRemove array then
-                    //we need to adjust the next index to remove since removing
-                    //elements at preceeding indices will shift the array elements.
-                    toRemove.append(l - toRemove.count)
+                    toRemove.append(l)
                     continue
                 }
                 edges[j][l].u -= 1

            var toRemove: [Int] = [Int]()
            for l in 0..<edges[j].count {
                if edges[j][l].v == index {
                    //if there are indices already in the toRemove array then
                    //we need to adjust the next index to remove since removing
                    //elements at preceeding indices will shift the array elements.
                    toRemove.append(l - toRemove.count)
                    continue

                    continue
                }
                if edges[j][l].v > index {
                    edges[j][l].v -= 1
                }
            }
            for f in toRemove {
                edges[j].remove(at: f)
            }
        }

                    edges[j][l].v -= 1
                }
            }
            for f in toRemove.reversed() {
                edges[j].remove(at: f)
            }
        }
