     }
     
     @objc public func migrateLegacyImageURLs(_ imageURLs: [URL], intoGroup group: String, completion: @escaping () -> Void) {
-        let moc = self.managedObjectContext
         let legacyCacheFolderURL = self.legacyCacheFolderURL
         let legacyCacheFolderPath = legacyCacheFolderURL.path
-        moc.perform {
+        perform { (moc) in
             let group = self.fetchOrCreateCacheGroup(key: group, moc: moc)
             for imageURL in imageURLs {
                 let key = self.cacheKeyForURL(imageURL)

                } catch let error {
                    DDLogError("Error moving cached file: \(error)")
                }
                
                moc.perform {
                    guard createItem else {
                        self.permanentCacheCompletionManager.complete(groupKey, identifier: identifier, enumerator: { (completion) in
                            completion.failure(ImageControllerError.fileError)

        guard permanentCacheCompletionManager.add(completion, priority: priority, forGroup: groupKey, identifier: identifier, token: token) else {
            return
        }
        let task = Background.manager.beginTask()
        perform { (moc) in
            if let item = self.fetchCacheItem(key: key, variant: variant, moc: moc) {
                if let group = self.fetchOrCreateCacheGroup(key: groupKey, moc: moc) {
                    group.addToCacheItems(item)
