Move global state to its own object to move things out of the XS file