Fix exit code

Tested on Linux, needs test on OS X.