better error handling and reporting