   (swap! memory-log conj s))
 
 (defn import-file [{:keys [content]}]
-  ;; (println "-----------------")
-  ;(println (str "import " content))
-  ;(println (str (imp/dance-perfect-xml->data (imp/read-xml-string content)))
-  ;(println "-----------------")
-  (imp/dance-perfect-xml->data (imp/read-xml-string content))
-  )
+  (imp/dance-perfect-xml->data (imp/read-xml-string content)))
 
-(defn event-msg-handler* [{:as ev-msg :keys [id ?data event ring-req]}]
-  (do
-    ;(logf (str "Event: " event))
-    (println (str "Id: " (:uid (:session ring-req))))
-    ;(println (str "Request : " ring-req))
-    (match [id ?data]
-           [:file/import xml]
-           (chsk-send! (:uid (:session ring-req)) [:file/imported {:content (import-file xml)}])
-           [:client/ping p] (chsk-send! 1 [:server/pong {:content 1}])
-           :else (println (str "Event : " event)))))
+(def message-chan (chan))
+(def message-send-chan (chan))
+
+;; (go (println (<! test-chan)))
+;; (>!! test-chan "Duudde")
+
+(def message-log (atom []))
+(def message-send-log (atom []))
+
+(go (while true
+      (let [msg (<! message-chan)]
+        (swap! message-log conj msg)
+        (message-dispatch msg message-send-chan))))
+
+(go (while true
+      (let [msg (<! message-send-chan)]
+        (swap! message-send-log conj msg)
+        (chsk-send! (:id msg) (:message msg)))))
+
+
+(defn message-dispatch [{:keys [topic payload sender]} out-chan]
+  (match [topic payload]
+         [:file/import xml]
+         (>!! out-chan {:id sender :message [:file/imported {:content (import-file xml)}]}) 
+         [:client/ping p]
+         (>!! out-chan {:id sender :message [:server/pong {:content 1}]})
+         :else (println (str "Unmatched message topicz: " topic))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Sente socket setup

(defroutes application-routes
  (GET "/" req "<h1>Tango on!</h1>")
  (GET "/admin" req {:body (slurp (clojure.java.io/resource "public/main.html"))
                     :session {:uid 1}
                     :headers {"Content-Type" "text/html"}})
  ;; Sente channel routes
  (GET  "/chsk" req (ring-ajax-get-or-ws-handshake req))

            [org.httpkit.server :as http-kit-server]
            [clojure.core.match :refer [match]]
            [tango.import :as imp]
            [ring.middleware.defaults :as defaults]
            [clojure.core.async
             :as a
             :refer [>! <! >!! <!! go chan buffer close! thread
                     alts! alts!! timeout]]
            ))

(def memory-log (atom []))

