         console.log "disconnected, retrying..."
         setTimeout(connect, 100)
 
-      peripheral.on "connect", -> peripheral.discoverServices ["2220"]
+      peripheral.on "connect", ->
+
+        process.on 'SIGINT', ->
+          peripheral.disconnect();
+          process.exit(0)
+
+        peripheral.discoverServices ["2220"]
 
       buffer = new Buffer(0)
 


            if stopBit != -1
              buffer = concatenate(buffer, data.slice(0, stopBit))
              process(buffer)
              buffer = data.slice(stopBit + 1)
            else
              buffer = concatenate(buffer, data)

    bufferB.copy(newBuffer, bufferA.length)
    newBuffer

  processData = (data) ->
      name = data.toString('ascii', 0, 9)
      format = data.toString('ascii', 10, 11)

