rename and re-factorize xhr CORS code