                 :data data
                 :id (guid)
                 :timestamp (.getTime (js/Date.))}]
-    (if (and (:connected? @cat) (or (:identified? @cat) (= action "identify")))
-      (do
-        (log "sending" (clj->js params))
-        (swap! cat update-in [:sent-messages] assoc (:id params) params)
-        (.send (:socket @cat) (stringify params)))
-      (do
-        (log "enqueing")
-        (swap! cat update-in [:queue] conj params)))))
+    (do-send cat params)))
 
 (defn flush-queue [cat]
   (log "identified, flushing queue")

        (let [id (guid)]
          (.setItem js/localStorage user id)
          id)))))

(declare send on-message on-open on-close)

(defn build-socket [host port]
  (js/WebSocket. (str "ws://" host ":" port "/api/ws")))

     (set-handlers! cat socket)
     cat)))

(defn do-send [cat params]
  (if (and (:connected? @cat) (or (:identified? @cat)
                                  (= (:action params) "identify")))
    (do
      (log "sending" (clj->js params))
      (swap! cat update-in [:sent-messages] assoc (:id params) params)
      (.send (:socket @cat) (stringify params)))
    (do
      (log "enqueing")
      (swap! cat update-in [:queue] conj params))))

(defn send [cat action data]
  (let [params {:api_key (:api-key @cat)
                :user (user)
