code refactor, starting on the CLI, old functionality works