refactored command add/delete code