Writing only the last states in state variables.