Rewrite the XArray to not use globals to cache state and use a context object instead