 
     private(set) var tortoises: [Tortoise] = []
     private(set) var commandHistories: [(tortoiseTag: Int, commandIndex: Int)] = []
-
-    // ⭐️ Add lock object.
-    private let lock = NSLock()
+    private var priorCommandHistoriesCount: Int = 0
+    private var commandHistoriesUnchangedCount: Int = 0
 
     var commandedHandler: ((TortoiseCharmer) -> Void)?
 

        assert(tortoiseCount > 0)
        tortoises = []
        commandHistories = []
        for index in 0..<tortoiseCount {
            let tortoise = Tortoise()
            tortoise.tag = index
            tortoise.commandedHandler = { [unowned self] (tortoise) in
                // ⭐️ Lock while writing commandHistories.
                defer { self.lock.unlock() }
                self.lock.lock()
                self.commandHistories.append((tortoiseTag: tortoise.tag,
                                              commandIndex: tortoise.commands.count - 1))
                self.commandedHandler?(self)


    @discardableResult
    func charm(with context: GraphicsContext, toFrame index: Int?) -> Int {
        let endIndex = commandHistories.count - 1
        let toIndex = min(max((index ?? endIndex), 0), endIndex)

