better error handling and error reporting