Fix exit codes

The previous implementation would exit successfully regardless of any error.