         if not is_search and clb
           clb.call @, json
 
-        @_cmds.splice(i, 1)
+        @_cmds.splice(index, 1)
         break
       else
         index++
 
-    switch json['command']
-      when 'registered'
-        @emit 'registered', json
-      when 'deregistered'
-        @emit 'deregistered', json
-      when 'speak'
-        @emit 'speak', json
-      when 'pmmed'
-        @emit 'pmmed', json
+
+  treatCommand: (json) ->
+    command = json['command']
+    switch command
       when 'nosong'
         @currentDjId   = null
         @currentSongId = null
         @emit 'endsong', @tmpSong
-        @emit 'nosong', json
       when 'newsong'
         if @currentSongId
           @emit 'endsong', @tmpSong
         @currentDjId   = json.room.metadata.current_dj
         @currentSongId = json.room.metadata.current_song._id
         @setTmpSong json
-        @emit 'newsong', json
       when 'update_votes'
         if @tmpSong
           @tmpSong.room.metadata.upvotes = json.room.metadata.upvotes
           @tmpSong.room.metadata.downvotes = json.room.metadata.downvotes
           @tmpSong.room.metadata.listeners = json.room.metadata.listeners
-        @emit 'update_votes', json
-      when 'booted_user'
-        @emit 'booted_user', json
-      when 'update_user'
-        @emit 'update_user', json
-      when 'add_dj'
-        @emit 'add_dj', json
       when 'rem_dj'
         if json.modid
-          json['command'] = 'escort'
           @emit 'escort', json
-        @emit 'rem_dj', json
-      when 'new_moderator'
-        @emit 'new_moderator', json
-      when 'rem_moderator'
-        @emit 'rem_moderator', json
-      when 'snagged'
-        @emit 'snagged', json
       when 'search_complete'
         query = json['query']
         for i in [0...@currentSearches.length]

    #console.log 'THIS IS WEIRD AND SHOULD NOT APPEAR.'


  onMessage: (msg) ->
    data = msg.data

    heartbeat_rgx = /~m~[0-9]+~m~(~h~[0-9]+)/
    if data.match heartbeat_rgx
      @_heartbeat data.match(heartbeat_rgx)[1]
      @lastHeartbeat = Date.now()
      @updatePresence()
      return

    @log "> #{data}"

    if msg.data == '~m~10~m~no_session'
      @userAuthenticate ->
        if not @_isConnected
          @getFanOf (data) ->
            @fanOf = data.fanof
            @updatePresence()
            # TODO: I don't like setInterval !
            setInterval(@updatePresence.bind(@), 10000)
            @emit 'ready'
        @callback()
        @_isConnected = true
      return

    @lastActivity = Date.now()

    len_rgx = /~m~([0-9]+)~m~/
    len = data.match(len_rgx)[1]
    json = JSON.parse(data.substr(data.indexOf('{'), len))
    index = 0
    while index < @_cmds.length
      [id, rq, clb] = @_cmds[index]

  log: (message) ->
    if @debug
      if @stdout == 'stderr'
        console.error message
      else
        console.log message


  connect: (roomId) ->
