fixes #8 - improve error handling