         return false
     }
     
-    fileprivate var databaseFilePath: URL? {
-        if storeType == NSSQLiteStoreType {
-            return workingFilesDirectory.appendingPathComponent("\(self.modelName).sqlite")
-        } else {
-            return nil
-        }
-    }
-}
-
+    private lazy var coordinator: NSPersistentStoreCoordinator = {
+        let model = self.managedObjectModel ?? self.objectModel
+        return NSPersistentStoreCoordinator(managedObjectModel: model)
+    }()
+    
+    private lazy var managedObjectContext: NSManagedObjectContext = {
+        Logging.log("Creating main context for \(self.identifier) - \(Thread.current.isMainThread)")
+        assert(Thread.current.isMainThread, "Main context should be crated on main thread")
+        
+        let mergePolicy = NSMergePolicy(merge: self.mergePolicy)
+        
+        let saving = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+        saving.persistentStoreCoordinator = self.persistentStoreCoordinator
+        saving.mergePolicy = mergePolicy
+        self.writingContext = saving
+        saving.name = "Saving"
+        
+        var managedContext = NSManagedObjectContext(concurrencyType: .mainQueueConcurrencyType)
+        managedContext.name = "Main"
+        managedContext.parent = self.writingContext
+        managedContext.mergePolicy = mergePolicy
+        
+        return managedContext
+    }()
+    
+    private lazy var objectModel: NSManagedObjectModel = {
+        let modelURL = Bundle.main.url(forResource: self.modelName, withExtension: "momd")!
+        return NSManagedObjectModel(contentsOf: modelURL)!
+    }()
+    
+    override func newBackgroundContext() -> NSManagedObjectContext {
+        let managedContext = NSManagedObjectContext(concurrencyType: .privateQueueConcurrencyType)
+        managedContext.parent = managedObjectContext
+        managedContext.mergePolicy = NSMergePolicy(merge: mergePolicy)
+        return managedContext
+    }
+}

    }
    
    public func perform(wait: Bool = true, block: @escaping ContextClosure) {
        let context = stack.mainContext!
        
        if wait {
            context.performAndWait {

    }
    
    public func save(completion: (() -> ())? = nil) {
        save(context: stack.mainContext, completion: completion)
    }
    
    private func save(context: NSManagedObjectContext, completion: (() -> ())? = nil) {
