Continuning the undo part from #438 here.
Continuning the undo part from #438 here.