             let applicationSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first! as NSString
             let path = applicationSupportDirectory.appendingPathComponent($0.key)
             if !$0.value.write(toFile: path, atomically: true) {
-                singleton.logger?.logWarning(message: String(format: "[%@] Failed to write imported data to %@.", classType(self), $0.key))
+                logger.logWarning(message: String(format: "[%@] Failed to write imported data to %@.", instanceType(self), $0.key))
             }
         }
 


class CoreDataController: NSObject {

    fileprivate static let singleton = CoreDataController()
    fileprivate var logger: LogController?

    lazy var persistentContainer: NSPersistentContainer = {
        let container = NSPersistentContainer(name: "Dough")
        self.logger?.logDebug(message: String(format: "[%@] About to load persistent store.", instanceType(self)))
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                self.logger?.logError(message: String(format: "[%@] Failed to load persistent store.", instanceType(self)), error: error)
            }
        })
        return container
    }()

    class func setLogger(logger: LogController) {
        singleton.logger = logger
    }

}

// MARK: Access
extension CoreDataController {

    class func perform(block: ((NSManagedObjectContext) -> Void)) {
        let context = singleton.persistentContainer.newBackgroundContext()
        singleton.logger?.logDebug(message: String(format: "[%@] Vending new context <%@>.", classType(self), context))
        block(context)
    }

    class func fetch<T>(_ request: NSFetchRequest<T>, context: NSManagedObjectContext) -> [T] {
        var results = [T]()
        do {
            results.append(contentsOf: try context.fetch(request))
        } catch {
          let message = String(format: "[%@] Error executing fetch request <%@> on context <%@>.", classType(self), request, context)
            singleton.logger?.logError(message: message, error: error)
        }
        return results
    }

    class func exportData() -> Data {
        let applicationSupportDirectory = NSSearchPathForDirectoriesInDomains(.applicationSupportDirectory, .userDomainMask, true).first! as NSString

        let sqlitePath = applicationSupportDirectory.appendingPathComponent(String(format: "%@.sqlite", Bundle.getAppName()))

// MARK: Persistence
extension CoreDataController {

    func save(context: NSManagedObjectContext) {
        logger.logDebug(message: String(format: "[%@] About to save changes to context <%@>.", instanceType(self), context))
        logger.logVerbose(message: String(format: "[%@] Changes:\ninserted: %@\ndeleted: %@\nupdated: %@, .", instanceType(self), context.insertedObjects, context.deletedObjects, context.updatedObjects))
        if !context.hasChanges {
            logger.logDebug(message: String(format: "[%@] No unsaved changes in context <%@>.", instanceType(self), context))
            return
        }

        do {
            try context.save()
        } catch {
            let message = String(format: "[%@] Could not save context <%@>.", instanceType(self), context)
            logger.logError(message: message, error: error)
        }
    }

