bugfix and refactoring CLI to more structured