Unit tests and CLI fixes