Diagnostics and error handling