first pass at improved error handling. to discuss.