CLI mode + some refactor