       (move-to-reservoir distribution [site-k skill agent-k]))
     (for [site-k (keys allocation)
           skill (keys site)]
-      (if (incomplete-alloc? site-k (get-in [site-k skill] allocation)
-                             static-data)
+      (if (pos? (demand (demand allocation [site-k skill] static-data)))
         (for [a (good-agents n-good-agents site-k skill reservoir static-data)]
           (allocate-max-bundle distribution [site-k skill] a static-data))))))
 

                   agents)))

(defn allocation-for-skill
  [location [skill n-needed] agents]
  (let [sorted-agents (sorted-map-by-distance location
                                              (filter-skill skill agents))]
    (loop [n-remaining n-needed

        allocs (map first allocs-agents)
        agents (map second allocs-agents)]
    [(into {} allocs) (into {} agents)]))

(defn allocate-full
  "Allocates as many units of skill as possible and needed to site with site-k,
  returning the new distribution."
  [{:keys allocation reservoir :as distribution} site-k skill static-data]
  (loop [available (good-agents (count (:agents static-data)) site-k skill
                                reservoir static-data)
         cur-distr distribution]
    (if (and (seq available)
             (pos? (demand allocation [site-k skill] static-data)))
      (recur (rest available)
             (allocate-max-bundle cur-distr [site-k skill] (first available)
                                  static-data))
      cur-distr)))

(defn find-single-distribution
  "For each skill needed by site site-k, allocates as many units of that skill
  as possible and needed to it. Returns the new distribution."
  [{:keys allocation reservoir :as distribution} site-k static-data]
  (let [allocator (fn [prev-distr skill] (allocate-full prev-distr site-k
                                                        skill static-data))]
    (reduce allocator distribution
            (keys (get-in static-data [:sites site-k :skills])))))

(defn find-initial-distribution [reservoir static-data]
  (let [allocator (fn [prev-distr site-k])])
  (reduce find-single-distribution {:allocation {} :reservoir reservoir}
          (keys (:sites static-data))))

;;; Credits: http://stackoverflow.com/questions/14488150/how-to-write-a-dissoc-in-command-for-clojure
(defn dissoc-in
