Cleanup and improving the error reporting.