     (swap! app-state assoc :current-track-id current-track-id)
     (swap! app-state assoc :current-sound-id current-sound-id)
 
-    (.emit socket "file-download-request" current-track-id)))
+    (request-file-download current-track-id)))
 
 (.on socket "set-loop"
   (fn [looping?]

         (:music-info @app-state))
    0))

(defn get-next-track-to-download []
  (letfn [(is-track-downloaded? [track-id]
            (contains? (:music-files @app-state) track-id))]
    (let [current-track-info (get-music-info-from-id (:current-track-id @app-state))]
      (loop [track-num (+ (.-tracknum current-track-info) 1)
             i 0]
        (if (>= i (count (:music-info @app-state)))
          nil
          (if (< track-num (count (:music-info @app-state)))
            (let [music-info (nth (:music-info @app-state) track-num)
                  track-id (.-id music-info)]
              (if-not (is-track-downloaded? track-id)
                track-id
                  (recur (+ 1 track-num)
                         (+ 1 i))))
              (recur 0
                     (+ 1 i))))))))

(defn request-new-track []
  (let [id (get-next-track-to-download)]
    (if-not (nil? id)
      (.emit socket "file-download-request" id))))

(defn pause []
  (player/pause)

    (.on stream "end"
      (fn []
        (println "Download complete!")
        (swap! app-state assoc :num-of-downloads (dec (:num-of-downloads @app-state)))
        (swap! app-state assoc :download-progress (dissoc (:download-progress @app-state) track-id))

        (if (> (:download-slots @app-state) (:num-of-downloads @app-state))
