Reorganize and test the CLI code.

This will resolve #12