             })
             
             if let index = taskIndex{
-                return self.tasks.remove(at: index)
+                return index
             }else{
                 return nil
             }

        // settings headers:
        task = session.dataTask(with: request) { (data, response, error) in
            
            self.removeTaskForRequest(request: r)
            DispatchQueue.main.async {
                
                if let completion = r.completion {
                    
                    if let r = error{
                        let result = Response(data: nil, error:error)
                        completion(result)
                        return
                        
                    }
                    
                    

    
    public func cancel(request:Request){
        
        let index = self.taskIndexForRequest(request: request)
        if let i = index {
            let task = self.tasks[i]
            task.cancel()
        }
        
        
        //taskToCancel?.cancel()
    }
    
    public func taskIndexForRequest(request:Request) -> Int?{
    
        if let taskId = self.taskIdByRequestID[request.requestId]{
            
