better error handling, fixes #144 and also resolves #128