Some refactoring of state.