              (let [resort (case time-type
                             :released reverse
                             :taken-marstime identity
-                            :taken-utc reverse)
-                   sorted (-> (sort-by time-type imgs) resort)]
-               [time-type (->> (sort-by time-type imgs)
+                            :taken-utc reverse)]
+               [time-type (->> imgs
+                            (sort-by time-type)
                             resort
-                            (map format-dates)
+                            (map format-image)
                             doall)]))))
+
+;;
+;; Transformations
+;;
 
 ;;
 ;; State & Main

(defn fetch-tick
  [old-imgs]
  (let [last-id (-> old-imgs first :id)
        new-imgs (parse-dates (fetch-images-since last-id))
        all-imgs (concat new-imgs old-imgs)]
    {:all all-imgs, :new new-imgs, :old old-imgs}))


            (recur (inc i) imgs')))))))

;;
;; Date Parsing/Unparsing
;;
;; Gotta store the dates as strings, but want them as Joda DateTime objects
;; to do sorting.
;;

(defn parse-dates
  [img]
  (let [strs (select-keys img times/types)
        dates (into {} (for [[type date-str] strs]
                         [type (times/rfc-parser date-str)]))
        lag (-> (time/interval (:taken-utc dates) (:released-utc dates))
              times/format-interval)]
    (-> (merge img dates)
      (assoc :lag lag))))

(defn unparse-dates
  [img]
  (let [dates (select-keys img times/types)]
    (into img (for [[type date] dates]
                [type (times/rfc-printer date)]))))

;;
;; Formatting
;;

(defn format-dates
  [img]
  (let [full-dates (select-keys img (disj times/types :taken-marstime))]
    (merge
      img
      {:taken-marstime (-> img :taken-marstime times/marstime-printer)}
      (into {} (for [[type date] full-dates]
                 [type (times/utc-printer date)])))))

(defn format-type
  [img]
  (let [type-code (:type img)
        formatted-type (condp = type-code
                         "B" "Subsampled Image"
                         "C" "Subsampled Image"
                         "D" "Subsampled Image"
                         "E" "Full Image"
                         "F" "Full Image"
                         "I" "Thumbnail"
                         "S" "Depth Map"
                         "T" "Thumbnail"
                         "U" "Depth Map"
                         (str "Type " type-code " Image"))]
    (assoc img :type formatted-type)))

(def format-image (comp format-dates format-type))

;;
;; AOT Sorting
;;

