   removeEdge: (node, port, node2, port2) ->
     @checkTransactionStart()
 
-    for edge,index in @edges
-      continue unless edge
-      if edge.from.node is node and edge.from.port is port
-        if node2 and port2
-          unless edge.to.node is node2 and edge.to.port is port2
-            continue
-        @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
-        @emit 'removeEdge', edge
-        @edges.splice index, 1
-      if edge.to.node is node and edge.to.port is port
-        if node2 and port2
-          unless edge.from.node is node2 and edge.from.port is port2
-            continue
-        @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
-        @emit 'removeEdge', edge
-        @edges.splice index, 1
+    toRemove = []
+    toKeep = []
+    if node2 and port2
+      for edge,index in @edges
+        if edge.from.node is node and edge.from.port is port and edge.to.node is node2 and edge.to.port is port2
+          @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
+          toRemove.push edge
+        else
+          toKeep.push edge
+    else
+      for edge,index in @edges
+        if (edge.from.node is node and edge.from.port is port) or (edge.to.node is node and edge.to.port is port)
+          @setEdgeMetadata edge.from.node, edge.from.port, edge.to.node, edge.to.port, {}
+          toRemove.push edge
+        else
+          toKeep.push edge
+
+    @edges = toKeep
+    for edge in toRemove
+      @emit 'removeEdge', edge
 
     @checkTransactionEnd()
 

  removeInitial: (node, port) ->
    @checkTransactionStart()

    for edge, index in @initializers
      continue unless edge
      if edge.to.node is node and edge.to.port is port
        @emit 'removeInitial', edge
        @initializers.splice index, 1

    @checkTransactionEnd()


  # ## Disconnected nodes
  #
  # Connections between nodes can be removed by providing the
  # nodes and ports to disconnect.
  #
  #     myGraph.removeEdge 'Display', 'out', 'Foo', 'in'
  #
