Improved error diagnostics