diff --git a/server/djrandom/frontend/static/player.js b/server/djrandom/frontend/static/player.js
index e17f31fc4f4c7b50ac1a316bdc3d0b52aa00ab46..84b0160f863fac6a7e3b9297e344ae9103b73174 100644
--- a/server/djrandom/frontend/static/player.js
+++ b/server/djrandom/frontend/static/player.js
@@ -109,22 +109,27 @@ djr.Playlist.prototype.allSongs = function() {
 };
 
 // Add a new chunk (only adds unique songs).
-// Returns the chunk ID.
+// Returns the chunk ID, or -1 if no songs were added.
 djr.Playlist.prototype.addChunk = function(playlist_chunk) {
   djr.debug('adding chunk to playlist ' + this.uuid);
   chunk_id = this.next_chunk_id++;
+
   var songs = [];
-  var playlist = this;
-  $.each(playlist_chunk.songs, function(idx, song) {
-    if (playlist.song_map[song]) {
-      return;
+  for (i = 0; i < playlist_chunk.songs.length; i++) {
+    if (this.song_map[song]) {
+      continue;
     }
-    songs.push(song);
-    playlist.song_map[song] = chunk_id;
-  });
-  this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs);
-  this.chunks.push(chunk_id);
-  return chunk_id;
+    songs.push(playlist_chunk.songs[i]);
+    this.song_map[playlist_chunk.songs[i]] = chunk_id;
+  }
+
+  if (songs.length == 0) {
+    return -1;
+  } else {  
+    this.chunk_map[chunk_id] = new djr.PlaylistChunk(songs);
+    this.chunks.push(chunk_id);
+    return chunk_id;
+  }
 };
 
 // Remove a chunk (by ID).