         label: 'disconnected'
       @emit 'disconnected'
 
-      if @getSerial and @getSerial()
-        @getSerial().close onClosed
+      if @transport
+        @transport.close onClosed
       else
         onClosed false
 
   updatecontainer: =>
-    return if !@container or !@graph
-    # TEMP
-
-  setupRuntime: (baudRate, serialPort, debugLevel) ->
-    @microfloGraph = {}
-    # FIXME: nasty and racy, should pass callback and only then continue
-    @debugLevel = debugLevel
-    @getSerial = null
-    try
-      @getSerial = microflo.serial.openTransport serialPort, baudRate, (err, transport) ->
-        console.log err, transport
-    catch e
-      console.log 'MicroFlo setup:', e
-
-  # Called every time the container has loaded successfully
-  onLoaded: =>
-    @connecting = false
-    @emit 'status',
-      online: true
-      label: 'connected'
-    @emit 'connected'
-
-    # Perform capability discovery
-    @send 'runtime', 'getruntime', null
-
-    @flush()
+    return unless @container
+    # Set an ID for targeting purposes
+    @container.id = 'preview-container'
 
   send: (protocol, command, payload) ->
     msg =

    @connecting = false
    @buffer = []
    @container = null
    super definition

  getElement: -> @container

    graph.on 'changeProperties', @updatecontainer
    super graph

  openComm: (serialPort, baudRate) ->
      microflo.serial.openTransport serialPort, baudRate, (err, transport) =>
        @connecting = false
        if err
          console.log 'MicroFlo error:', err
          @emit 'error', err
          return
        @transport = transport

        @emit 'status',
          online: true
          label: 'connected'
        @emit 'connected'

        # Perform capability discovery
        @send 'runtime', 'getruntime', null
        @flush()

  connect: ->
    return if @connecting
    @connecting = true
    @microfloGraph = {}

    # TODO: remove hardcoding of baudrate and debugLevel
    baudRate = 9600
    serialPort = @getAddress().replace 'serial://', ''

    # Make sure serial transport is closed before reopening
    if @transport
      @transport.close () =>
        @transport = null
        @openComm serialPort, baudRate
    else
        f = () =>
          @openComm serialPort, baudRate
        setTimeout f, 0

  disconnect: ->
    onClosed = (success) ->
