Fixed a bug in CLI and added tests