 
 (defonce print-lock (Object.))
 
-(defn log [out from msg]
+;; using an agent so log writes don't delay messages
+(defonce write-agent (agent {}))
+
+(defn log [agent-state out from msg]
   (let [text (with-out-str (pprint msg))]
     (prn [:msg from (count text)])
     (locking print-lock

        (println ";; ----------------------------------------")
        (println ";; -- FROM " from)
        (println ";; ----------------------------------------")
        (println text))
      )))

(defn client-loop [id client to-port]
  (let [target (Socket. "localhost" to-port)

              #(do (try
                     (loop []
                       (when-some [target-msg (transport/recv target-transport)]
                         (send write-agent log log-out :target target-msg)
                         (transport/send client-transport target-msg)
                         (recur)))
                     (catch Exception e
