refactor and expand CLI.