Cleanup and improve CLI.
Improve CLI interface. Fix some bugs.