       :insecure? true})
     (func)))
 
-(defn fetch-all-channel-locs
-  "Fetch all channels from remote server and return a sequence of
-  channel locs within the zipper"
-  [base-url]
-  (-> base-url
-      (str "/channels")                 ;combine the base url with the rest path
-      (client/get                       ;fetch the channels via rest
-       {:insecure? true})
-      :body                             ;extract the response body
-      to-zip                            ;get an xml zipper
-      (zx/xml-> :list :channel)         ;get a loc per channel
-      ))
+(defn fetch-all
+  "Fetch everything at url from remote server and return a sequence of
+  channel locs based on the supplied predicates. In other words - grab
+  the xml from the url via a GET request, extract the :body of the
+  result, parse the XML, create a 'zipper', and return the result of
+  the query (predicates)"
+  [url predicates]
+  (as-> url v
+    (client/get v {:insecure? true})
+    (:body v)
+    (to-zip v)
+    (apply zx/xml-> v predicates)))
 
-(defn process-channel
-  "Take a channel zip and write to the filesystem"
-  [chanzip]
-  (let [channel-name (zx/xml1-> chanzip :name zip/down zip/node)
-        channel-xml (xml/indent-str (zip/node chanzip))
-        base-dir "blarfnarg" ;; (java.util.UUID/randomUUID)
-        file-path (str base-dir "/" channel-name)]
+(defn serialize-node
+  "Take an xml location and write to the filesystem with a meaningful
+  name and path"
+  [dirname xmlloc name-predicate]
+  (let [name (apply zx/xml1-> xmlloc name-predicate)
+        xml-str (xml/indent-str (zip/node xmlloc))
+        file-path (str "blarfnarg/" dirname (File/separator) "/" name)]
     (io/make-parents file-path)
-    (spit file-path channel-xml)))
+    (spit file-path xml-str)))
+
+(defn run-channels [base-url]
+  (doseq [loc (fetch-all (str base-url "/channels") [:list :channel])]
+    (serialize-node "channels" loc [:name zip/down zip/node])))
+
+(defn run-codeTemplates [base-url]
+  (doseq [loc (fetch-all (str base-url "/codeTemplates") [:list :codeTemplate])]
+    (serialize-node "codeTemplates" loc [:name zip/down zip/node])))
 
 (defn makeitso
   "App logic"
   [base-url username password]
   (with-authentication base-url username password
-    #(map process-channel (fetch-all-channel-locs base-url))))
+    (fn [] (do
+            (run-channels base-url)
+            (run-codeTemplates base-url)))))
 
 (defn -main
   [& args]

             [zip :as zip]]
            [clojure.data.xml :as xml]
            [clojure.data.zip.xml :as zx]
            [clojure.java.io :as io]))

(defn to-zip
  "Takes a string of xml and returns an xml zipper"

(defn with-authentication
  "Binds a cookie store to keep auth cookies, authenticates using the
  supplied url/credentials, and returns the results of executing the
  supplied parameterless function for side effects"
  [base-url username password func]
  (binding [clj-http.core/*cookie-store* (clj-http.cookies/cookie-store)]
    (client/post
