       edgeArray = node.pos.concat(node.neighbors[0].pos)
     else
       edgeArray = node.neighbors[0].pos.concat(node.pos)
-    for i in [0...@curIndex]
+    for i in [0...@curIndex[index]]
       found = true
       for j in [0..5]
         found &= Math.abs(@routes[index].geometry.__vertexArray[6 * i + j] - edgeArray[j]) < 0.01
       if found
         edgesIndex = i
         break
+
+    # swap edges
     for i in [0..5]
       @routes[index].geometry.__vertexArray[edgesIndex * 6 + i] =
-        @routes[index].geometry.__vertexArray[(@curIndex - 2) * 6 + i]
+        @routes[index].geometry.__vertexArray[(@curIndex[index] - 2) * 6 + i]
     
 
     @curIndex[index]--

      return

    index = @getIndexFromTreeId(@route.getTree().treeId)
    for i in [0...@curIndex]
      if @nodes[index].geometry.nodeIDs[i] == node.id
        nodesIndex = i
        break

    for i in [0..2]
      @nodes[index].geometry.__vertexArray[nodesIndex * 3 + i] =
        @nodes[index].geometry.__vertexArray[(@curIndex - 1) * 3 + i]

    # Delete Edge by finding it in the array
    # ASSUMPTION edges always go from smaller ID to bigger ID

    newNode.doubleSided = true
    @nodesSpheres.push(newNode)
    @trigger "newGeometries", [newNode]

  getIndexFromTreeId : (treeId) ->
    unless treeId
      treeId = @route.getTree().treeId
