Refactor a bit the CLI code