Why do you need to rebuild the `state` object for this? Could this be written in terms of the `x` and `xw` objects instead?