better error handling scheme, fixes #27