Add tests, fix exit code issues