Refactor work with state.