Changes to writeState()