                (concat (reverse (sort (dep/topo-comparator deps) changed))
                        unload))
       :load (distinct
-             (filter (complement (set removed))
+             (filter (complement (set removed-names))
                      (concat (sort (dep/topo-comparator new-deps) changed)
                              load))))))
 

  need to be reloaded after files were removed."
  [state files]
  (let [{:keys [load unload deps namespaces]} state
        removed (keep (comp second namespaces) files)
        new-deps (reduce dep/remove-key deps removed)
        changed (affected-namespaces deps removed)]
    (assoc state
      :namespaces (apply dissoc namespaces files)
      :deps new-deps

            [clojure.tools.namespace :as tns]
            [clojure.tools.namespace.dependency :as dep]))

(defn- remove-deps [deps decls]
  (reduce dep/remove-key deps (map second decls)))

(defn- add-deps [deps decls]
  (reduce (fn [ds decl]
            (let [nn (second decl)]
              (reduce (fn [g dep] (dep/depend g nn dep))
                      ds (tns/deps-from-ns-decl decl))))
          deps decls))

(defn- update-deps [deps decls]
  (-> deps
      (remove-deps decls)
      (add-deps decls)))

(defn- affected-namespaces [deps names]
  (apply set/union
         (set names)
         (map #(dep/transitive-dependents deps %) names)))

(defn tracker
  "Returns a new namespace dependency tracker."
