Improved exception handling

Closes #80