Trying to improve error handling, but not quite sure why exceptions are not being caught.
Fixing issue #3