Extract state into something separate that we can use to track data flow