Improved CHECK_ERR macro and fixed potential variable name conflict.