             performAuthentication(request.task, completionHandler: completionHandler)
             
         default:
+            
+            self.callbacks[request.task.taskIdentifier] = nil
             
             completionHandler(statusCode: statusCode, data: response.data, error: response.result.error)
         }

                callback(error)
            }
            
            guard error == nil else {
                
                if let error = error where error.code == 504 {
                    
                    authenticationStrategy.retries = 0
                    
                    self.resumeAll()
                    
                    return completionHandler(statusCode: NSURLError.UserCancelledAuthentication.rawValue, data: nil, error: error)
                }
                
                let delay = dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC)))
                
                dispatch_after(delay, dispatch_get_main_queue()) {
                    self.performAuthentication(task, completionHandler: completionHandler, authenticationCallback: authenticationCallback)
                }
                
                return

        
        manager.startRequestsImmediately = true
        
        manager.session.getTasksWithCompletionHandler { dataTasks, uploadTasks, downloadTasks in
            
            for task in dataTasks {
                self.resume(task, identifier: task.taskIdentifier, accessToken: accessToken)
            }
            
            for task in uploadTasks {
                self.resume(task, identifier: task.taskIdentifier, accessToken: accessToken)
            }
            
            for task in downloadTasks {
                self.resume(task, identifier: task.taskIdentifier, accessToken: accessToken)
            }
        }
        
        while let (identifier, task) = self.pendingRequests.popFirst() {
            self.resume(task, identifier: identifier, accessToken: accessToken)
        }
    }
    
    private func resume(task :NSURLSessionTask, identifier :Int, accessToken :String? = nil) {
        
        guard let token = accessToken else {
            return task.resume()
        }
        
        guard let request = task.originalRequest?.URLRequest else {
            return task.resume()
        }
        
        guard let callback = self.callbacks[identifier] else {
            return task.resume()
        }
        
        if let authenticationStrategy = self.authenticationStrategy {
            request.setValue(token, forHTTPHeaderField: authenticationStrategy.authenticationHeader)
        }
        
        self.request(request) { (statusCode, data, error) in
            callback(statusCode: statusCode, data: data, error: error)
            
            self.callbacks[identifier] = nil
            
            task.cancel()
        }
    }
}