Revert "Revert "rebuild state""

This reverts commit ab5fe585a954946c0311d5445353acd11e9e2a7d.