 					}
 				}
 				
-				
-				_children = to
-				let range = index..<(index + size)
-				let to = flattened
-				if range.count < TransitionItemsLimit && to.count < TransitionItemsLimit {
-					treeController.replaceNodes(at: range, with: to)
-				}
-				else {
-					UIView.performWithoutAnimation {
+				if from != nil, let treeController = treeController, let index = flatIndex {
+					let size = self.size
+					
+					_children = to
+					let range = index..<(index + size)
+					let to = flattened
+					if range.count < TransitionItemsLimit && to.count < TransitionItemsLimit {
 						treeController.replaceNodes(at: range, with: to)
 					}
+					else {
+						UIView.performWithoutAnimation {
+							treeController.replaceNodes(at: range, with: to)
+						}
+					}
+				}
+				else {
+					_children = to
 				}
 			}
 			else {
 				_children = to
 			}
+			
 			for child in from ?? [] {
 				child.parent = nil
 			}

		}
	}
	
//	private struct Update {
//		var insertSection: [Int: TreeNode] = [:]
//		var deleteSection = IndexSet()
//		var insertObject: [IndexPath: TreeNode] = [:]
//		var deleteObject = [IndexPath]()
//		var moveObject: [IndexPath: IndexPath] = [:]
//		var update: [IndexPath: Any] = [:]
//	}
//	private var update: Update?
	
	func controllerWillChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
		//		guard objectNode != nil else {return}
//		self.update = Update()
		treeController?.beginUpdates()
	}
	
	func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange sectionInfo: NSFetchedResultsSectionInfo, atSectionIndex sectionIndex: Int, for type: NSFetchedResultsChangeType) {
//		guard update != nil else {return}
//		guard let sectionNode = self.sectionNode else {return}
//		switch type {
//		case .insert:
//			update?.insertSection[sectionIndex] = sectionNode.init(section: sectionInfo, objectNode: self.objectNode)
//		//			children.insert(sectionNode.init(section: sectionInfo, objectNode: self.objectNode), at: sectionIndex)
//		case .delete:
//			update?.deleteSection.insert(sectionIndex)
//		//			children.remove(at: sectionIndex)
//		default:
//			break
//		}
	}
	
	func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChange anObject: Any, at indexPath: IndexPath?, for type: NSFetchedResultsChangeType, newIndexPath: IndexPath?) {
//		guard update != nil else {return}
//		switch type {
//		case .insert:
//			update?.insertObject[newIndexPath!] = objectNode.init(object: anObject as! ResultType)
//		case .delete:
//			update?.deleteObject.append(indexPath!)
//		case .move:
//			if (sectionNode == nil && (children[indexPath!.row] as! FetchedResultsObjectNode<ResultType>).object === anObject as! ResultType) ||
//				(sectionNode != nil && (children[indexPath!.section].children[indexPath!.row] as! FetchedResultsObjectNode<ResultType>).object === anObject as! ResultType) {
//				update?.deleteObject.append(indexPath!)
//				update?.insertObject[newIndexPath!] = objectNode.init(object: anObject as! ResultType)
//			}
//		case .update:
//			update?.update[newIndexPath!] = anObject
//		}
	}
	
	
	func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
		/*guard let update = update else {return}
		var children = self.children

		if sectionNode == nil {
			for i in update.deleteObject.sorted(by: > ) {
				children.remove(at: i.row)
			}
			for (i, value) in update.insertObject.sorted(by: {$0.key < $1.key}) {
				children.insert(value, at: i.row)
			}
		}
		else {
			for i in update.deleteObject.filter({!update.deleteSection.contains($0.section)}).sorted(by: > ) {
				children[i.section].children.remove(at: i.row)
			}
			if !update.deleteSection.isEmpty {
				children.remove(at: update.deleteSection)
			}
			for i in update.insertSection.sorted(by: {$0.key < $1.key}) {
				children.insert(i.value, at: i.key)
			}

			for (i, value) in update.insertObject.filter({update.insertSection[$0.key.section] == nil}).sorted(by: {$0.key < $1.key}) {
				children[i.section].children.insert(value, at: i.row)
			}
		}
		self.children = children*/
		
		if let sectionNode = self.sectionNode {
			children = resultsController.sections?.map {sectionNode.init(section: $0, objectNode: self.objectNode)} ?? []
		}
		else {
			children = resultsController.fetchedObjects?.flatMap {objectNode.init(object: $0)} ?? []
		}

		treeController?.endUpdates()
		//		update.update.forEach {

		}
		
		set {
			
			let from = _children
			let to = newValue

			if !isInBatch {
				if let from = _children {
					var set = Set(from)
					for a in to {
