Issue #28: adding some more error handling