         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 =

    graph.on 'changeProperties', @updatecontainer
    super graph

  connect: ->
    unless @container
      throw new Error 'Unable to connect without a parent element'

    # Make sure serial transport is closed before reopening
    if @getSerial and @getSerial()
      @getSerial().close () ->
        #

    # Let the UI know we're connecting
    @connecting = true
    @emit 'status',
      online: false
      label: 'connecting'

    # Set an ID for targeting purposes
    @container.id = 'preview-container'

    # Update container contents as needed
    @on 'connected', @updatecontainer

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

    # HACK: sends initial message, which hooks up receiving as well
    @onLoaded()

  disconnect: ->
    onClosed = (success) ->

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

    # MicroFlo things
    @transport = null
    @microfloGraph = null
    @debugLevel = 'Error'

    @on 'connected', @updatecontainer

    super definition

  getElement: -> @container
