 
 (defn handle-append-entries-response [state p]
   (if (pos? (get-in p [:body :count])) ; heart beat response
-    (check-and-update-append-entries state p)
+    (l/check-and-update-append-entries state p)
     (update state :clients cs/inc-heartbeats (:src p))))
 
 (defn client-read
   [state pkt]
   (let [[s response] (cs/add-read state pkt)]
     (if (= :broadcast-heart-beat response)
-      (broadcast-heartbeat s)
+      (l/broadcast-heartbeat s)
       (utils/transmit s response))))
 
 (defn- handle-get [state p]
   (client-read state p))
 
-(defn- handle-packet [state]
+(defn- handle-packet
+  [state]
   (let [p (first (:rx-queue state))
         s (check-term state p)]
     (condp = (:type p)
       :get (handle handle-get s p)
       :set (handle handle-set s p)
       :cas (handle handle-cas s p)
-      :request-vote (handle-request-vote s p)
-      :request-vote-reply (handle-request-vote-response s p)
-      :append-entries (handle-append-entries s p)
+      :request-vote (f/handle-request-vote s p)
+      :request-vote-reply (c/handle-request-vote-response s p)
+      :append-entries (f/handle-append-entries s p)
       :append-entries-response (handle-append-entries-response s p))))
 
 (defn- process-rx-packets [state]

  (->
   (update state :election-timeout - dt)
   (apply-commit-index)
   (utils/if-not-leader? check-election-timeout)
   (process-rx-packets)
   (utils/if-leader? check-backlog dt)
   (utils/if-leader? cs/check-clients)))

(defn set-peers [state peers]

(defn- apply-commit-index [state]
  (if (> (:commit-index state) (:last-applied state))
    (-> (update state :last-applied inc)
        (update :db #(log/apply-entry state %)))
    state))

(defn- redirect-to-leader [state p]
