Tweaked argument names, added variables, refractored logic for getting X-RequestDigest if needed