CLI code refactoring