Better error handling, fixes #8