Moved a potentially confusing global to be function-local & fixed a few comments