       if (@state != 'inactive')
         return
 
-      # cleanup
+      _cleanup()
+      return
+
+    _cleanup: () ->
       @chunkType = null
       if (@destinationNode)
         @destinationNode.disconnect()

        blob: blob
      }

      console.log(recording)

      @em.dispatchEvent(new CustomEvent('recording', { detail: { recording: recording } }))

      @chunks = []


    # Called each time a chunk of recording becomes available
    _onDataAvailable: (evt) ->
      @chunks.push(evt.data)
      @chunkType = evt.data.type

