Improved Error Reporting Function