         group: payload.group
         data: payload.data
 
-  addNode: (node, graph) ->
-    return unless node
-
-    return if node.dataflowNode?
-
-    return if graph.nodes.findWhere({nofloId: node.id})?
-
-    @addNodeRuntime node, graph.nofloGraph.runtime
+  addNode: (nfNode, dfGraph) ->
+    return unless nfNode
+
+    return if nfNode.dataflowNode?
+
+    #HACK to not add twice
+    return if dfGraph.nodes.findWhere({nofloId: nfNode.id})?
+
+    @addNodeRuntime nfNode, dfGraph.nofloGraph.runtime
 
     # Load the component
-    dfNode = graph.nofloGraph.runtime.getComponentInstance node.component,
-      id: node.id
-      label: ( if node.metadata.label? then node.metadata.label else node.id )
-      x: ( if node.metadata.x? then node.metadata.x else 500 )
-      y: ( if node.metadata.y? then node.metadata.y else 300 )
-      parentGraph: graph
+    dfNode = dfGraph.nofloGraph.runtime.getComponentInstance nfNode.component,
+      id: nfNode.id
+      label: ( if nfNode.metadata.label? then nfNode.metadata.label else nfNode.id )
+      x: ( if nfNode.metadata.x? then nfNode.metadata.x else 500 )
+      y: ( if nfNode.metadata.y? then nfNode.metadata.y else 300 )
+      parentGraph: dfGraph
 
     # Reference one another
-    node.dataflowNode = dfNode
-    dfNode.nofloNode = node
-
-    graph.nodes.add dfNode
+    nfNode.dataflowNode = dfNode
+    dfNode.nofloNode = nfNode
+
+    dfGraph.nodes.add dfNode
 
   addNodeRuntime: (node, runtime) ->
     runtime.sendGraph 'addnode',

      component: node.component
      metadata: node.metadata

  addEdge: (edge, graph) ->
    return unless edge

    @addEdgeRuntime edge, graph.nofloGraph.runtime

    unless edge.dataflowEdge
      Edge = @dataflow.module 'edge'
      edge.metadata = {} unless edge.metadata
      dfEdge = new Edge.Model
        id: edge.from.node + ":" + edge.from.port + "::" + edge.to.node + ":" + edge.to.port
        parentGraph: graph
        source: edge.from
        target: edge.to
        route: if edge.metadata.route? then edge.metadata.route else 0

      # Reference one another
      dfEdge.nofloEdge = edge
      edge.dataflowEdge = dfEdge

    # Add to Graph
    graph.edges.add dfEdge

  addEdgeRuntime: (edge, runtime) ->
    runtime.sendGraph 'addedge',


  subscribeDataflowEdge: (edge, graph) ->
    unless edge.nofloEdge
      # try
      edge.nofloEdge = graph.nofloGraph.addEdge edge.source.parentNode.nofloNode.id, edge.source.id, edge.target.parentNode.nofloNode.id, edge.target.id,
        route: edge.get 'route'
      # catch error
        # Not added, probably multiple w/o array port https://github.com/noflo/noflo/issues/90

    edge.on 'change:route', ->
      edge.nofloEdge.metadata.route = edge.get 'route'

  subscribeNoFloEvents: (graph, runtime) ->
    graph.on 'addNode', (nfNode) =>
      @addNode nfNode, graph.dataflowGraph
      @dataflow.plugins.log.add 'node added: ' + nfNode.id
    graph.on 'removeNode', (nfNode) =>
      if nfNode.dataflowNode?
        nfNode.dataflowNode.remove()
      @dataflow.plugins.log.add 'node removed: ' + nfNode.id
      runtime.sendGraph 'removenode',
        id: nfNode.id
    graph.on 'addEdge', (nfEdge) =>
      @addEdge nfEdge, graph.dataflowGraph
      @dataflow.plugins.log.add 'edge added.'
    graph.on 'removeEdge', (nfEdge) =>
      if nfEdge.from.node? and nfEdge.to.node?
        if nfEdge.dataflowEdge?
          nfEdge.dataflowEdge.remove()
      @dataflow.plugins.log.add 'edge removed.'
      runtime.sendGraph 'removeedge',
        from: nfEdge.from
        to: nfEdge.to
    graph.on 'addInitial', (iip) =>
      @addInitial iip, graph.dataflowGraph
      @dataflow.plugins.log.add 'IIP added: ' + JSON.stringify(iip)
