refactored and added "checkthenadd" command