Refactoring and cleanup CLI client