   (let [[address port] (str/split a #":")]
     {:address address :port (Integer/parseInt port)}))
 
-(defn s->millepoch-time [s]
-  (.getTimeInMillis (clojure.instant/read-instant-calendar s)))
-
-(defn millepoch-time-now []
-  (.getTime (java.util.Date.)))
-
-(defn update-backends [backends config]
+(defn update-backends [backends config listener]
   (let [existing (keys backends)
         wanted (keys (:backends config))
-        unwanted (clojure.set/difference (set existing) (set wanted))]
+        unwanted (set/difference (set existing) (set wanted))]
+    (println ["unwanted " unwanted])
     (run! close! (map #(:chan (get backends %)) unwanted))
     (reduce (fn [m [n v]]
               (let [a (parse-address (:listen-address v))]
                 (assoc m
                        n
-                       (or ;(get backends n)
+                       (or (get backends n)
                            (assoc v
                                   :name n
-                                  :chan (backend-chan (:address a) (:port a))
+                                  :chan
+                                  (backend-chan (:address a) (:port a) listener)
                                   :last-seen-at-ms
                                   (if-let [ls (:last-seen-at v)]
                                     (s->millepoch-time ls)

    h))

(defn run-server [prefix]
  (let [config-ch (merlion.core/combined-config-watcher prefix)
        shutdown (chan)]
    (go
      (loop [backends {}
             listener nil
             config {}]
        (let [timestamp (- (millepoch-time-now) (* 10 1000))
              healthy (healthy-backends timestamp backends)
              [val ch] (alts!
                        (conj
                         (map #(vector (:chan %) listener)
                              healthy)
                         config-ch
                         shutdown))]
          (cond (= ch config-ch)
                (recur (update-backends backends val)
                       (update-listener listener val)
                       val)

                (= ch shutdown)
                (do (println "quit") (.close listener))

        listener
        (let [new-l (ServerSocketChannel/open)]
          (and listener (.close listener))
          (doto new-l
            (.configureBlocking false)
            (.bind (InetSocketAddress. req-port))))))
    nil))

(defn combined-config-watcher [prefix]
