undo/redo and some command legality refactoring