 
   closeConnection: ->
     return if not @connected
+
     if @socket
       try
         @socket.end()
+
     @connected = false
     @connecting = false
+
     for own i of @currentJobs
       if @currentJobs[i]
         @currentJobs[i].abort()
         @currentJobs[i].emit "error", new Error "Job failed"
       delete @currentJobs[i]
+
     for own i of @currentWorkers
       @currentWorkers[i].finished = true if @currentWorkers[i]
       delete @currentWorkers[i]
+
     @init()
 
   errorHandler: (err) ->

  processCommandQueue: (chunk) ->
    if @commandQueue.length is 0
      @processing = false
      return 
    @processing = true
    @sendCommandToServer.apply @, @commandQueue.shift()


      @processCommandQueue()
    if @connected or @connecting
      return false

    @connecting = true
    console.log "connecting..." if @debug
    @socket = (netlib.connect or netlib.createConnection) @port, @host

    @socket.on "connect", =>
      @socket.setKeepAlive true
      @connecting = false
