Exit handling with status code

Hi, here's the code as discussed in #72. Cheers