             [cemerick.friend :as friend]
             (cadence [model :as model]
                      [state :as state]
-                     [config :as config]
+                     [config :refer [storage read-config]]
                      [routes :refer [app-routes]]
                      [security :refer [friend-settings]])
             (compojure [route :as route]


(defn attempt-model-connection []
  (try
    (model/connect config/storage)
    (catch java.io.IOException e
      (println "ERROR: Could not connect to MongoDB."))
    (catch java.lang.NullPointerException e
      (println "ERROR: Could not authenticate with Mongo. See config: \n\t"
               (str (assoc config/storage :password "**********"))))))

(def app
  "Create the application from its routes and middlewares."


(defn -main
  "Run the application."
  ([options] (let [mode (:mode options
                               (if (= (read-config "PRODUCTION" "no") "yes")
                                 :production
                                 :development))
                   port (:port options
                               (Integer. (read-config "PORT" "5000")))]
               (attempt-model-connection)
               (state/merge {:mode mode :port port})
               (run-server (if (state/production?)
