 final class MoaImageDownloader {
   var task: NSURLSessionDataTask?
   var cancelled = false
-
+  
   deinit {
     cancel()
   }
-
+  
   func startDownload(url: String, onSuccess: (UIImage)->(),
     onError: (NSError, NSHTTPURLResponse?)->()) {
-
+    
     cancelled = false
-
+  
     task = MoaHttpImage.createDataTask(url,
       onSuccess: onSuccess,
       onError: { [weak self] error, response in
         if let currentSelf = self
           where !currentSelf.cancelled { // Do not report error if task was manually cancelled
-
+    
           onError(error, response)
         }
       }
     )
-
+      
     task?.resume()
   }
-
+  
   func cancel() {
     task?.cancel()
     cancelled = true

  static func createDataTask(url: String,
    onSuccess: (NSData, NSHTTPURLResponse)->(),
    onError: (NSError, NSHTTPURLResponse?)->()) -> NSURLSessionDataTask? {

    if let nsUrl = NSURL(string: url) {
      return createDataTask(nsUrl, onSuccess: onSuccess, onError: onError)
    }

    // Error converting string to NSURL
    onError(MoaHttpErrors.InvalidUrlString.new, nil)
    return nil
  }

  private static func createDataTask(nsUrl: NSURL,
    onSuccess: (NSData, NSHTTPURLResponse)->(),
    onError: (NSError, NSHTTPURLResponse?)->()) -> NSURLSessionDataTask? {

    return NSURLSession.sharedSession().dataTaskWithURL(nsUrl) { (data, response, error) in
      if let httpResponse = response as? NSHTTPURLResponse {
        if error == nil {

      onError(error, response)
    }
  }
  
  private static func validMimeType(mimeType: String) -> Bool {
    let validMimeTypes = ["image/jpeg", "image/pjpeg", "image/png"]
    return contains(validMimeTypes, mimeType)
