 import Foundation
 import Siesta
 
-private let stubPropertyKey = "\(NetworkStub.self).stub"
-
-final class NetworkStub: URLProtocol
-    {
-    private static var stubs = [RequestStub]()
-    private static var requestInitialization = Latch(name: "initialization of requests")
+final class NetworkStub
+    {
+    private static var _stubs = [RequestStub]()
+    private static let stubsAccessQueue = DispatchQueue(label: "NetworkStub.stubs access")
 
     static var defaultConfiguration: URLSessionConfiguration
         { wrap(URLSessionConfiguration.ephemeral) }
 
     static func wrap(_ configuration: URLSessionConfiguration) -> URLSessionConfiguration
         {
-        configuration.protocolClasses = [Self.self]
+        configuration.protocolClasses = [StubbedNetworkProtocol.self]
         return configuration
         }
 

        return stub
        }

    static func add(_ stub: RequestStub)
        {
        synchronized
            { stubs.insert(stub, at: 0) }
        }

    static func clearAll()
        {
        Self.requestInitialization.await
            {
            synchronized { stubs = [] }
            }
        }

    override class func canInit(with request: URLRequest) -> Bool


        let body = extractBody(from: request)

        let stubs = NetworkStub.stubs
        guard let stub = stubs.first(where: { $0.matcher.matches(request, withBody: body) }) else
            {
            fatalError(
