Fix error handling and reporting