updated error handling and mailing