update commandAdd for undo work with compartments, refactoring