Fix for issue #65 - improve error handling