better error handling, fixes issue #139