 (.on socket "track-change"
   (fn [track-id]
     (println "CHANGING TO TRACK " track-id)
-    (swap! app-state assoc :current-track-id track-id)
-
-    (if-not (nil? (:current-sound @app-state))
-      (.destruct (:current-sound @app-state)))
+    (let [last-current-track-id (:current-track-id @app-state)]
+      (swap! app-state assoc :current-track-id track-id)
+
+      (if-not (or
+                (= last-current-track-id track-id)
+                (nil? last-current-track-id))
+        (destroy-track last-current-track-id)))
 
     (if (nil? (get (:music-files @app-state) track-id))
       (.emit socket "file-download-request" track-id)

  (println "Song has finished!")
  (.emit socket "track-complete"))

(defn play-track [track-id position]
  (let [reader (new js/FileReader)
        song-blob (get (:music-files @app-state) track-id)]

                          :download-slots default-download-slots
                          :num-of-uploads 0
                          :num-of-downloads 0
                          :download-progress {}
                          :tracks-to-delete []}))

(enable-console-print!)

