             let authKey = getAuthKey(),
             let signingData = buildRequestSigningString(mutableRequest).data(using: String.Encoding.utf8),
             let sig = authKey.compactSign((signingData as NSData).sha256_2()) {
-            mutableRequest.setValue("bread \(token):\((sig as NSData).base58String())", forHTTPHeaderField: "Authorization")
-        }
-        return mutableRequest.copy() as! URLRequest
+            let hval = "bread \(token):\((sig as NSData).base58String())"
+            mutableRequest.setValue(hval, forHTTPHeaderField: "Authorization")
+        }
+        return mutableRequest as URLRequest
     }
     
     open func dataTaskWithRequest(_ request: URLRequest, authenticated: Bool = false,

}

func isBreadChallenge(_ r: HTTPURLResponse) -> Bool {
    if let challenge = getHeaderValue("www-authenticate", d: r.allHeaderFields as Dictionary<NSObject, AnyObject>) {
        if challenge.lowercased().hasPrefix("bread") {
            return true
        }

        
        func put(_ key: String, value: [UInt8], version: UInt64,
                 completionFunc: @escaping (UInt64, Date, BRRemoteKVStoreError?) -> ()) {
            var req = URLRequest(url: client.url("/kv/1/\(key)"))
            req.httpMethod = "PUT"
            req.addValue("\(version)", forHTTPHeaderField: "If-None-Match")
            req.addValue("application/octet-stream", forHTTPHeaderField: "Content-Type")
            req.addValue("\(value.count)", forHTTPHeaderField: "Content-Length")
            var val = value
            req.httpBody = Data(bytes: &val, count: value.count)
            client.dataTaskWithRequest(req, authenticated: true, retryCount: 0) { (dat, resp, err) in
                if let err = err {
                    self.client.log("[KV] PUT key=\(key) err=\(err)")
                    return completionFunc(0, Date(timeIntervalSince1970: 0), .unknown)
