Exit with the correct status

Fixes #351