Improved usage of exit codes in CLI commands

Includes some light cleaning in api operations
Improved revert operation to add better handling of conflict cases