Fix undo sometimes not working