     private var streamDelegate: FPSStreamDelegate? {
         return (_underlyingSession.delegate as? FPSStreamDelegate)
     }
-    private var _underlyingTaskObject: NSURLSessionTask?
     private var _taskIdentifier: Int
+    
+    @available(iOS 9.0, OSX 10.11, *)
+    static var streamTasks = [Int: NSURLSessionStreamTask]()
     
     @available(iOS 9.0, OSX 10.11, *)
     internal var _underlyingTask: NSURLSessionStreamTask? {
-        get {
-            return _underlyingTaskObject as? NSURLSessionStreamTask
-        }
-        set {
-            _underlyingTaskObject = newValue
-        }
+        return FPSStreamTask.streamTasks[_taskIdentifier]
     }
     
     public override var taskIdentifier: Int {

        if #available(iOS 9.0, OSX 10.11, *) {
            _underlyingTask!.closeWrite()
        } else {
            write(true)
        }
    }
    

//  FPSStreamTask.swift
//  FileProvider
//
//  Created by Amir Abbas Mousavian.
//  Copyright © 2016 Mousavian. Distributed under MIT license.
//

import Foundation
