Fix issue 69 error handling

This pull request fixes the issue described in issue#69. As noted there, it depends on and includes the commits of a prior pull request. 

It has been manually tested.