 
   onSocketConnection: (socket) =>
     socket.on 'DynamicMode', (data) =>
+      return unless @is_enabled
       value = JSON.parse data.toString()
-      return unless @is_enabled
       return if @is_on == value
       @log.debug "DynamicMode is being turned #{value}"
       @is_on = value
       @checkDynamicMode()
       @onStatusChanged()
-    
+
   checkDynamicMode: =>
     return unless @is_enabled
     return unless @mpd.library.artists.length

  restoreState: (state) =>
    @is_on = state.status.dynamic_mode ? false
    @random_ids = state.status.random_ids ? {}

  saveState: (state) =>
    state.status.dynamic_mode = @is_on
    state.status.dynamic_mode_enabled = @is_enabled
    state.status.random_ids = @random_ids

  setConf: (conf, conf_path) =>
    @is_enabled = true


    if @is_on
      commands = []
      delete_count = Math.max(current_index - @history_size, 0)
      for i in [0...delete_count]
        commands.push "deleteid #{item_list[i].id}"
      add_count = Math.max(@future_size + 1 - (item_list.length - current_index), 0)

      commands = commands.concat ("addid #{JSON.stringify file}" for file in @getRandomSongFiles add_count)
      @mpd.sendCommands commands, (msg) =>
