     }
 }
 
-private protocol CoreStack {
-    var mainContext: NSManagedObjectContext! { get }
-    var managedObjectModel: NSManagedObjectModel? { get set }
-    var databaseFilePath: URL? { get }
-    func performUsingWorker(closure: @escaping ((NSManagedObjectContext) -> ()))
-    var identifier: String { get }
-    var persistentStoreCoordinator: NSPersistentStoreCoordinator { get }
-    func loadPersistentStores(completion: @escaping (() -> ()))
-}
-
-@available(iOS 10, tvOS 10.0, *)
-private class CoreDataStack: CoreStack {
-    private let modelName: String!
-    private lazy var container: NSPersistentContainer = {
-        let container: NSPersistentContainer
-        if let model = self.managedObjectModel {
-            container = NSPersistentContainer(name: self.modelName, managedObjectModel: model)
-        } else {
-            container = NSPersistentContainer(name: self.modelName)
-        }
-        
-        let config = NSPersistentStoreDescription()
-        config.url = self.databaseFilePath
-        config.type = self.storeType
-        container.persistentStoreDescriptions = [config]
-        
-        return container
-    }()
-    fileprivate var mainContext: NSManagedObjectContext! {
-        return container.viewContext
-    }
+private class CoreStack {
+    fileprivate let modelName: String
+    fileprivate let type: String
+    fileprivate let identifier: String
+    private let directory: FileManager.SearchPathDirectory
+    fileprivate let mergePolicy: NSMergePolicyType
+    fileprivate let wipeOnConflict: Bool
     fileprivate var managedObjectModel: NSManagedObjectModel?
-    fileprivate let identifier: String
     fileprivate var persistentStoreCoordinator: NSPersistentStoreCoordinator {
-        return container.persistentStoreCoordinator
-    }
-    
-    private var workerCount = 0
-    private let storeType: String
-    private let directory: FileManager.SearchPathDirectory
+        fatalError()
+    }
+    internal var mainContext: NSManagedObjectContext {
+        fatalError()
+    }
     
     init(modelName: String, type: String = NSSQLiteStoreType, identifier: String, in directory: FileManager.SearchPathDirectory = .documentDirectory, mergePolicy: NSMergePolicyType = .mergeByPropertyObjectTrumpMergePolicyType, wipeOnConflict: Bool) {
+        
         self.modelName = modelName
+        self.type = type
         self.identifier = identifier
-        self.storeType = type
         self.directory = directory
-    }
-    
-    fileprivate func performUsingWorker(closure: @escaping ((NSManagedObjectContext) -> ())) {
-        Logging.log("Main: \(container.viewContext) - \(container.viewContext.parent) - \(container.viewContext.persistentStoreCoordinator)")
-        container.performBackgroundTask() {
-            context in
-            
-            if context.name == nil {
-                self.workerCount += 1
-                context.name = "Worker \(self.workerCount)"
-            }
-            
-            Logging.log(">>> \(context) - \(context.parent) - \(context.persistentStoreCoordinator)")
-            
-            closure(context)
-        }
-    }
-    
-    fileprivate func loadPersistentStores(completion: @escaping (() -> ())) {
-        assert(container.managedObjectModel != nil)
-        container.loadPersistentStores {
-            storeDescription, error in
-            
-            self.container.viewContext.automaticallyMergesChangesFromParent = true
-            try! self.container.viewContext.setQueryGenerationFrom(.current)
-            
-            print(">>>>>>>>> Store: \(storeDescription)")
-            
-            if let error = error as NSError? {
-                fatalError("Unresolved error \(error), \(error.userInfo)")
-            }
-
-            DispatchQueue.main.async(execute: completion)
-        }
+        self.mergePolicy = mergePolicy
+        self.wipeOnConflict = wipeOnConflict
     }
     
     fileprivate var databaseFilePath: URL? {
-        if storeType == NSSQLiteStoreType {
-            return workingFilesDirectory.appendingPathComponent("\(self.modelName!).sqlite")
+        if type == NSSQLiteStoreType {
+            return workingFilesDirectory.appendingPathComponent("\(self.modelName).sqlite")
         } else {
             return nil
         }
     }
     
-    public lazy var workingFilesDirectory: URL = {
+    private lazy var workingFilesDirectory: URL = {
         let urls = FileManager.default.urls(for: self.directory, in: .userDomainMask)
         let last = urls.last!
         let dbIdentifier = self.identifier + ".db"

        return false
    }
    
    fileprivate var databaseFilePath: URL? {
        if storeType == NSSQLiteStoreType {
            return workingFilesDirectory.appendingPathComponent("\(self.modelName).sqlite")
        } else {
            return nil
        }
    }
}


    }
    
    public lazy var mainContext: NSManagedObjectContext = {
        let context = self.stack.mainContext
        context.name = "Main"
        return context
    }()
