           mpdEvent tracks_to_add.length, 'onPlaylistUpdate', ->
             count += 1
             eq mpd.playlist.item_list.length, count
-            eq track.name, mpd.playlist.item_list[count-1].track.name
-            eq track.file, mpd.playlist.item_list[count-1].track.file
-            eq track.time, mpd.playlist.item_list[count-1].track.time
-            eq track.artist, mpd.playlist.item_list[count-1].track.artist
+            eq tracks_to_add[count-1].name, mpd.playlist.item_list[count-1].track.name
+            eq tracks_to_add[count-1].file, mpd.playlist.item_list[count-1].track.file
+            eq tracks_to_add[count-1].time, mpd.playlist.item_list[count-1].track.time
+            eq tracks_to_add[count-1].artist, mpd.playlist.item_list[count-1].track.artist
 
             if count < tracks_to_add.length
               mpd.queueFile tracks_to_add[count].file

      ok /^playlist:/m.test(msg)
      ok /^repeat:/m.test(msg)
      ok /^random:/m.test(msg)
  ->
    lets_test "remove event listeners"
    count = 0

            
            mpd.removeEventListeners 'onPlaylistUpdate'


            lets_test "playing a track"
            id_to_play = mpd.playlist.item_list[mpd.playlist.item_list.length-1].id
            count = 0
            mpdEvent 3, 'onStatusUpdate', ->
              # call updateStatus again to flush the event queue
              mpd.updateStatus()
              return if count++ < 3
              mpd.removeEventListeners 'onStatusUpdate'

              eq mpd.status.state, "play"
              eq mpd.status.current_item.id, id_to_play

            mpd.playId id_to_play
          mpd.queueFile tracks_to_add[count].file
        mpd.clear()
      mpd.updateArtistInfo random_artist.name
 
    mpd.updateArtistList()
]

runTest = (test, args...) ->
