                                        (set old-uploads-order))
         removed-upload-ids (set/difference (set old-uploads-order)
                                            (set uploads-order))
-        update-vals (fn [f m vals] (reduce #(update % %2 f)
+        update-vals (fn [m keys f] (reduce #(update % %2 f)
                                            m
-                                           vals))]
+                                           keys))]
     (cond
       (< (count active-uploads) upload-slots)
       (assoc new-state 
              :uploads
-              (update-vals start
-                           uploads 
-                           (take (- upload-slots
-                                    (count active-uploads)) 
-                                 uploads-order)))
+             (update-vals uploads
+                          (take (- upload-slots
+                                   (count active-uploads)) 
+                                unpaused-inactive-uploads)
+                          start))
       
-      ;(> (count active-uploads) upload-slots)
-      ;new-state
+      (> (count active-uploads) upload-slots)
+      (assoc new-state
+             :uploads
+             (update-vals uploads
+                          (drop upload-slots
+                                active-uploads)
+                          stop))
 
       :else new-state)))
 

        new-uploads (:uploads new-state)
        old-upload (old-uploads upload-id)
        new-upload (new-uploads upload-id)]
    (when-not (= :hash (:type old-upload))
      (cond
        (and (not (:stopped? new-upload))

(ns moomoo-frontend.uploads
  (:require [clojure.set :as set :refer [difference]]))

; paused? refers to when user manually pauses an upload
; stopped? refers to the upload being stopped because
; of the upload limit
(def blank-upload {:stopped? true
                   :paused?  false
                   :id       nil
