undo stack refactoring.