     last = null
     # Queue next command to execute (since we're pipelining, we wait for
     # the previous command to complete and send its output first).
-    queue = (stream, argv)->
+    queue = (context, argv)->
       command = {}
       # Invoke this command.
       command.invoke = ->
         if fn = commands[argv[0]]
           console.log "Executing #{argv.join(" ")}" if debug
           argv[0] = command.reply
-          fn.apply {}, argv
+          fn.apply context, argv
         else
           command.reply ERROR, "Unknown command #{argv[0]}"
       # Send a reply back to the client and if there's another command
       # in the queue, invoke it next.
       command.reply = (type, value)->
-        respond stream, type, value
+        respond context.stream, type, value
         last = command.next if last == command
         # Invoke next command in queue.
         if command.next

            if argv.length == argc
              # We have all the arguments we expect, run a command and
              # reset argc/argv to await the next command.
              queue stream, argv
              argc = 0
              argv = []
            # See if we have more input to process.
            return process(stream, input) if input.length > 0
        else
          # We're here because we expect to read the argument length:
          # $<number of bytes of argument 1> CR LF

    commands.ECHO = (reply, text)->
      reply SINGLE, text

    # Resets the context.  Discards current browser.
    commands.RESET = (reply)->
      this.reset()
      reply SINGLE, "OK"

    # Tells browser to visit <url>.
    #
    # Replies with OK.
    commands.VISIT = (reply, url)->
      this.browser.visit url
      reply SINGLE, "OK"
    # Tells browser to wait for all events to be processed.
    #
    # Replies with error or OK.
    commands.WAIT = (reply)->
      this.browser.wait (err)->
        if err
          reply ERROR, err.message
        else
