Refactored CLI and added tests for it.