     }
 
     private func createTempDir(path: String) {
-        if let tempDirectory = NSURL(fileURLWithPath: self.documentDirectory).URLByAppendingPathComponent(path),
-            let tempDirectoryPath = tempDirectory.path {
+        if let tempDirectory = NSURL(fileURLWithPath: self.documentDirectory).URLByAppendingPathComponent(path) {
             
-            if self.fileManager.fileExistsAtPath(tempDirectoryPath) == false {
-                do {
-                    try self.fileManager.createDirectoryAtPath(tempDirectoryPath, withIntermediateDirectories: true, attributes: nil)
-                } catch let error as NSError {
-                    NSLog("Unable to create directory \(error.debugDescription)")
-                }
+            createDirectoryIfNotExist(tempDirectory)
+        }
+    }
+    
+    private func createDirectoryIfNotExist(directoryURL: NSURL?){
+        if let path = directoryURL?.path where self.fileManager.fileExistsAtPath(path) == false {
+            do {
+                try self.fileManager.createDirectoryAtPath(path, withIntermediateDirectories: true, attributes: nil)
+            } catch let error as NSError {
+                NSLog("Could not create directory at path:\(path) because of the following error: \(error.debugDescription)")
             }
         }
     }


    private func registerLogDebugMethod() {
        let logDebug: @convention(block) (String, String) -> () = { message, key in
            print("\n\n>>>>>>>> \(key): \(message)\n\n")
        }
        context.setObject(unsafeBitCast(logDebug, AnyObject.self), forKeyedSubscript: "logDebug")
    }

						}
					} else {
						var hasError = false
                        if let isReachable = NetworkReachability.sharedInstance.isReachable where isReachable == false {
                            // No internet connection
                            hasError = true
                        } else if NetworkReachability.sharedInstance.isReachableViaWiFi() == false && self?.isWhitelistedUrl(requestedUrl) == false {
                            // do not download large files if user is not on WiFi
                            hasError = true
                        } else if method == "GET" {
							ConnectionManager.sharedInstance
								.sendRequest(.GET,
											 url: requestedUrl,
