```\nfunction setState(uint delegationId, State newState) internal {\n    TimeHelpers timeHelpers = TimeHelpers(contractManager.getContract("TimeHelpers"));\n    DelegationController delegationController = DelegationController(contractManager.getContract("DelegationController"));\n\n    require(newState != State.PROPOSED, "Can't set state to proposed");\n\n    if (newState == State.ACCEPTED) {\n        State currentState = getState(delegationId);\n        require(currentState == State.PROPOSED, "Can't set state to accepted");\n\n        \_state[delegationId] = State.ACCEPTED;\n        \_timelimit[delegationId] = timeHelpers.getNextMonthStart();\n    } else if (newState == State.DELEGATED) {\n        revert("Can't set state to delegated");\n    } else if (newState == State.ENDING\_DELEGATED) {\n        require(getState(delegationId) == State.DELEGATED, "Can't set state to ending delegated");\n        DelegationController.Delegation memory delegation = delegationController.getDelegation(delegationId);\n\n        \_state[delegationId] = State.ENDING\_DELEGATED;\n        \_timelimit[delegationId] = timeHelpers.calculateDelegationEndTime(delegation.created, delegation.delegationPeriod, 3);\n        \_endingDelegations[delegation.holder].push(delegationId);\n    } else {\n        revert("Unknown state");\n    }\n}\n```\n