 (def counter (atom 0))
 (def customer-cut (atom 0))
 (def HAIRCUT-TIME 2500)
-(def SPAWN-TIME 1000)
+(def SPAWN-TIME '(1000 2000))
+
+(def HAIRCUT-TIME 20)
+(def SPAWN-TIME '(10 30))
 (def PRINT-TIME 600)
-(def printer (agent []))
+(def printer (agent 0))
+(def LEVEL 20)
+
+(defn myprint [level & more]
+  (if (>= level LEVEL)
+    (do
+      ;(println @printer level)
+      ;(send-off printer inc)
+      (apply println more)
+      ;(send-off printer (fn [msgcount] (apply println more) (inc msgcount)))
+      )))
 
 (defn err-handler-fn [ag ex]
   (println "error occured: " ex " and we still have value " @ag)

    []))

(defn print-world []
  (println "\n**********")
  (println "Barber: " @barber-chair)
  (println "Queue: " (seq @queue-chairs))
  (printf "Customer visited: %d, cut: %d\n" @counter @customer-cut)
  (println "=============\n"))

(defn print-loop [who]
  (while true
    (print-world)
    (Thread/sleep PRINT-TIME)))

(send printer print-loop)

(defn spawn [time]
  (println "Spawning")
  (Thread/sleep time)
  (send shop add-customer)
  time)

(while true
  (spawn SPAWN-TIME))


(set-error-handler! barber err-handler-fn)
(set-error-handler! shop err-handler-fn)
(set-error-handler! printer err-handler-fn)

(declare do-haircut)

(defn next-client [who]
  (reset! barber-chair [])
  (myprint 10 "barber is handling next client")
  (if (> (count @queue-chairs) 0)
    (let [next-customer (peek @queue-chairs)]
      (swap! queue-chairs pop)
      (myprint 10 "Barber will cut " next-customer " and those are waiting" @queue-chairs)
      (do-haircut next-customer))
    (myprint 10 "barber is going to sleep")))

(defn wake-up [barber customer]
  (do-haircut customer))

(defn do-haircut [customer]
  (myprint 11 customer "is getting haircut")
  (swap! barber-chair conj customer)
  (Thread/sleep HAIRCUT-TIME)
  (myprint 11 customer "got haircut")
  (swap! customer-cut inc)
  (send-off barber next-client))

(defn wait-for-haircut [customer]
  (if (< (count @queue-chairs) 3)
    (swap! queue-chairs conj customer)
    (myprint 12 "Barber is busy and no place for" customer))
  customer)

(defn customer-action [customer]
