 import UIKit
 import CoreData
 
+let CoreDataWriteQueue: dispatch_queue_t = dispatch_queue_create("BraveDataWriteQueue", DISPATCH_QUEUE_SERIAL)
+
 class DataController: NSObject {
     static let singleton = DataController()
     
     private var _managedObjectContext: NSManagedObjectContext? = nil
     var managedObjectContext: NSManagedObjectContext? {
         get {
-            if NSThread.isMainThread() == true {
+            if NSThread.isMainThread() {
                 return mainThreadContext()
-            } else {
+            }
+            else {
                 return writeContext()
             }
         }

        if managedObjectContext.hasChanges {
            do {
                try managedObjectContext.save()
            } catch {
                fatalError("Error migrating store: \(error)")
            }
        }
    }
    

            return managedObjectContext!
        }
        
        if let coordinator: NSPersistentStoreCoordinator = self.persistentStoreCoordinator {
            managedObjectContext = NSManagedObjectContext(concurrencyType: .MainQueueConcurrencyType)
            managedObjectContext?.persistentStoreCoordinator = coordinator
            managedObjectContext?.undoManager = nil
            managedObjectContext?.mergePolicy = NSErrorMergePolicy
            
