Revert "Revert "Rewrite the Exit code.""

This reverts commit 48e25abdd59702f1e649e8fa29ead5e07a768f4b.