        (generate-query-string query-params)))
 
 (defn- generate-signature [method uri query-params]
-  (let [url (URL. uri)
+  (let [query-params (into (sorted-map) query-params)
+        url (URL. uri)
         host (lower-case (.getHost url))
         path (get-path url)
         data (url-to-sign method host path query-params)]

  [method uri params]
  (let [query-params (merge params auth-params)
        signature (generate-signature method uri query-params)
        query-string (generate-query-string (merge query-params {"Signature" signature}))]
    (str uri "?" query-string)))


;(build-url "get" "https://www.test.com" {"a" "1"})

(defn- bytes [str]
  (.getBytes str "UTF-8"))

(defn- base64 [b]
  (Base64/encodeBase64String b))

(defn- get-mac []
  (let [signing-key (SecretKeySpec. (bytes (aws-secret)) hmac-sha256-algorithm)
        mac (Mac/getInstance hmac-sha256-algorithm)]
    (.init mac signing-key)
    mac))

(defn- calculate-hmac [data]
  (try
    (let [mac (get-mac)
          raw-mac (.doFinal mac (bytes data))]
      (base64 raw-mac))
    (catch Exception e
