Undo + Dirty fixes, refactoring