CLI tests and fix a bug