Change some error handling for better diagnostics