More robust error handling
Merge pull request #14 from Hedwig188/master

Fix issue #12