Error handling, fixes #9