
274 N.W.2d 331 (1979)
STATE of Iowa, Appellee,
v.
Gary Robert GRIMME, Appellant.
No. 62021.
Supreme Court of Iowa.
January 24, 1979.
Rehearing Denied March 15, 1979.
*332 *333 Paul J. Kaufman, of Leifker Law Offices, Dubuque, for appellant.
Richard C. Turner, Atty. Gen., and James Schilling, Dubuque, Asst. County Atty., for appellee.
Considered by REYNOLDSON, C. J., and LeGRAND, McCORMICK, ALLBEE and McGIVERIN, JJ.
McCORMICK, Justice.
The principal question here is whether defendant Gary Robert Grimme was denied due process under the Fourteenth Amendment of the United States Constitution when he was removed from a drug treatment facility and sentenced to prison without an evidentiary hearing. Defendant raised this question in a motion in arrest of judgment which was overruled by the trial court.[1] We hold that defendant was denied due process, reverse the court's order, and remand for further proceedings.
Defendant was charged with delivery of a schedule I controlled substance in violation of § 204.401(1)(a), The Code, based upon an alleged sale of one gram of heroin to a state agent on July 22, 1976. He pled guilty to the charge on June 10, 1977. After a presentence investigation, the court found defendant to be dependent on controlled substances within the meaning of § 204.409(2) and on July 14, 1977, committed him for treatment to ADAPT, a private drug treatment facility located in Des Moines.
Approximately two weeks later the trial court received a communication from ADAPT and on August 1, 1977, entered an order reciting defendant had become unacceptable to ADAPT and requiring him to be brought before the court for sentencing on August 4, 1977.
At the proceeding on August 4, the court called the administrator of ADAPT as a witness to explain why the agency found defendant unacceptable. Counsel for defendant, Russel Neuwoehner, asked to make a statement for the record, and permission was granted. His statement was as follows:
On behalf of the defendant I would like to state to the Court that my only information as to the alleged rule or violation that the defendant has committed is contained in the Court's order of August 1st, 1977, as well as a long distance telephone conversation I had with the defendant wherein he was somewhat unsure of what was going on. Because of that we would reserve the right, after hearing Mr. McCarthy's testimony, to request the Court that this hearing be adjourned and continued to enable us to prepare whatever appropriate response we feel is necessary. Because Mr. McCarthy has traveled a long distance, and what he has to *334 say, I think, is important for the defense to hear, we would be willing to go ahead at this time, but reserve the right to at least make application for a continuance.
In response the court said:
Yes. You can make application, but for the record, it's the Court's position that under the Section under which the defendant was found guilty, 204.401, prison sentence is mandatory. There is no discretion to the Court. However, where under 204.409, the Court finds that there is a dependency, the Court may then commit the defendant to therapeutic institution. The Court's experience has been that for the type of dependency the defendant has, there is no therapeutic institution that can do any good that isn't structured, and the only structured institution of that type in Iowa is ADAPT. And consequently what the Court was confronted with is that the only suitable housing for the defendant had become unacceptable or unavailable to him, and the Court had to do something with the defendant since he was not acceptable to ADAPT. And to the Court's mind, he was denied all benefit of 204.409 since there was no reasonable alternative. The Court is further of the opinion that once the guilty plea is entered, that the matter of the consideration of determining disposition of the matter is not available to the defendant for scrutiny or cross-examination, but the practice of the Court has been to, as a matter of grace and not right, make available to the defendant those matters that are in the Court's mind, at least, that lead to the conclusion. So, before any ruling adverse to the defendant, the Court will consider permitting application for hearing. However, there will have to be suitable provisions for custody pending any such further delay.
Testimony of the ADAPT administrator then commenced. During the course of his testimony, the administrator said ADAPT was willing to give defendant another chance. The trial court then terminated the proceeding with the following comments:
I'm not going to ask you for any commitment, Mr. Grimme, because I wouldn't be too interested in it one way or the other. As I said, my situation at the outset, to my mind, there is only one place where therapy is available to you, and there is only one thing that will keep you out of the penitentiary, and that's therapy. So, it's entirely your problem. You were here today because you were unacceptable to ADAPT. You have become acceptable to ADAPT. As long as you are acceptable to ADAPT, you may stay there. When you become unacceptable to ADAPT, you will go to the penitentiary. It's like that.
The defendant having become acceptable to ADAPT, the order of July 14th, 1977, is restored in full force and effect, and the sheriff is directed to return the defendant to ADAPT to resume his therapy therein.
On September 27, 1977, the trial court received a new report from ADAPT finding defendant "inappropriate and unacceptable" for its program. The court ordered him returned for sentencing.
When defendant was brought before the court on September 30, the following occurred:
THE COURT: This is State of Iowa vs. Gary R. Grimme, Criminal No. 13090, coming on for imposition of judgment and sentence pursuant to plea of guilty heretofore entered. Let the record show the defendant personally present and represented by counsel. Is there any lawful reason why judgment should not be imposed upon the defendant at this time?
MR. NEUWOEHNER: Your Honor, at this time the defendant would wish to state that he was ordered to ADAPT, a treatment facility on the 14th day of July, 1977, by order of this Court, which order stated that the defendant was dependent upon controlled substances within the meaning of Section 204.409 subparagraph 2, and that he was being sentenced to said facility under that subparagraph. The defendant would object *335 to proceeding at this time, your honor, for the reason that, quoting in part from sub-section, sub-paragraph 2 of Section 204.409, down throughit's a lengthy paragraphit states, in part, "If it's established thereafter to the satisfaction of the Court that the person has again violated any provisions of this Chapter, he may be returned to the custody or sentenced upon his conviction as provided by law." This provision taking place after an individual has been sent to a treatment facility. We are not possessed of any information which indicates that the defendant has again violated the Chapter, and feel that the Court therefore does not have the authority to return the defendant and sentence him in accordance with law unless a showing is made that a violation of the Chapter has occurred.
We would further state that the Court made a determination in its order of July 14, 1977, that the defendant is addicted or dependent upon drugs. We have not received any report on any showing that this situation or status has changed, and we would object to proceeding because the defendant has not been granted the opportunity for rehabilitation as set forth in Section 204.409 of the Code.
If the Court does not feel that these objections are proper, the defendant would request to withdraw his previously entered plea of guilty and enter a plea of not guilty.
THE COURT: The Court's interpretation of that Chapter 204, is that the imposition of judgment prior to, during or after the therapy provided for in 204.409 is entirely discretionary and goes to the Court's discretion. The Court finds no impropriety in the motion entered or objections entered, but finds they are not well founded, and overrules. And finds no good cause for permission of the defendant to withdraw his guilty plea. And the Court will proceed to sentence of the defendant.
Defendant subsequently obtained present counsel who filed a motion in arrest of judgment in his behalf, alleging several grounds. They included allegations of (1) denial of due process in failing to conduct an evidentiary hearing with accompanying safeguards before terminating his commitment to ADAPT and sentencing him to prison, (2) termination of the commitment to ADAPT contrary to the provisions of § 204.409(2), (3) error in refusing to give him an accommodation hearing, and (4) imposition of an excessive sentence.
Attorney Neuwoehner and defendant testified at the hearing on the motion. Mr. Neuwoehner said he had received no notice of any alleged misconduct of defendant when he was returned for sentencing on September 30. All he knew was that the court order said ADAPT had found him unacceptable. In explaining his failure to request an evidentiary hearing when defendant was provided the opportunity for allocution at sentencing, he said:
My testimony was based uponmy earlier testimony today was based upon what I recall as the Court's communications at the earlier hearing, and communications prior to the sentencing which left me with the distinct impression that there was not going to be any evidence heard, and that the motion was the extent of what the Court would entertain at that time. I'm speaking from memory, but my recollection of the first time that Mr. Grimme was brought back, the Court admonished him to the point that he would not receive a hearing if he was brought back, or at least that was the impression that was left with me.
Defendant's testimony included the following:
Q. At the time you were sentenced, do you know the specific reasons for which the Court found you uncooperative? A. No. I was never really aware of anything which I believed would constitute imposition of sentence; anything that I had done to be uncooperative that would cause the Court to remove me from the ADAPT facility and sentence me.
Q. If you were provided an opportunity prior to the sentence being imposed upon you, would you have given evidence on your own behalf? A. Yes, I would.

*336 Q. Without going into it in any detail, very briefly, state what that evidence would have been. A. Well, I felt that my performance and evaluation while I was in the facility could be more or less backed up by the testimony of other residents and people who were on the staff in the facility itself. And I would also attempt to verify what substantial gains I have made through participation in the program myself.
Defendant testified he had not been advised he had a right to request an accommodation hearing despite his plea of guilty to the delivery charge, and attorney Neuwoehner confirmed that testimony.
The trial court overruled the motion in arrest of judgment, holding that defendant's right of allocution had afforded him an opportunity to make whatever showing he wished in resisting judgment. The court found the objection which was raised on that occasion was "not supported by law". The court also held that an accommodation hearing would have been fruitless because defendant had admitted the truth of the State's minutes of testimony during the guilty plea proceeding.
I. The due process claim. Defendant's due process contention arises from principles enunciated in Morrissey v. Brewer, 408 U.S. 471, 92 S.Ct. 2593, 33 L.Ed.2d 484 (1972). If an individual is threatened with State action which will deprive him of life, liberty or property, he is entitled to due process. What process is due depends upon the nature of the government function and individual interest involved.
In Morrissey the Supreme Court recognized that a parolee has a protected interest in his continued liberty. A probationer's interest in avoiding incarceration is similarly protected. Gagnon v. Scarpelli, 411 U.S. 778, 93 S.Ct. 1756, 36 L.Ed.2d 656 (1973). Even a prisoner's interest in earning good time credit is a protected liberty. Wolff v. McDonnell, 418 U.S. 539, 94 S.Ct. 2963, 41 L.Ed.2d 935 (1974). See also Baxter v. Palmigiano, 425 U.S. 308, 96 S.Ct. 1551, 47 L.Ed.2d 810 (1976). In contrast, when state law authorizes a prisoner to be placed in any of its prisons, no liberty interest is implicated by transfer of an inmate between them without hearing. Meachum v. Fano, 427 U.S. 215, 96 S.Ct. 2532, 49 L.Ed.2d 451 (1976).
Defendant's status as a resident of ADAPT was closer to that of a probationer than that of a prisoner. He was not in prison, not even having been sentenced. The commitment was an alternative to imprisonment, designed under § 204.409(2), to permit him to overcome his drug dependency and thereby earn a chance to avoid the otherwise mandatory maximum term of incarceration. His sentence could be remitted in whole or in part, and he could be placed on probation and remain out of prison. In these circumstances we hold that defendant had a liberty interest while committed to ADAPT which could not be taken from him without due process.
Cases decided in other jurisdictions in analogous situations are in accord. See United States v. Taylor, 305 F.Supp. 1150 (E.D.N.Y.1969); United States v. Thornton, 344 F.Supp. 249 (D.Del.1972); In re Bye, 12 Cal.3d 96, 115 Cal.Rptr. 382, 524 P.2d 854 (1974), cert. denied, sub nom. Procunier v. Bye, 420 U.S. 996, 95 S.Ct. 1437, 43 L.Ed.2d 679 (1975); Ball v. Jones, 43 A.D.2d 281, 351 N.Y.S.2d 199 (1974), modified on other grounds, sub nom. Pannell v. Jones, 36 N.Y.2d 339, 368 N.Y.S.2d 467, 329 N.E.2d 159 (1975). Although In re Bye and Ball v. Pannell involved termination of outpatient status rather than termination of commitment itself, the principle is similar.
We must next decide what process was due defendant before his commitment to ADAPT could be terminated.
Notice and opportunity for hearing are essential to procedural due process. Auxier v. Woodward State Hospital-School, 266 N.W.2d 139, 142 (Iowa 1978). We believe due process requires that a defendant's commitment to a drug treatment facility under § 204.409(2) not be terminated for misconduct or unacceptability until he *337 receives (1) written notice of the grounds alleged to justify terminating his commitment, (2) disclosure of the evidence against him, (3) the opportunity to be heard and to present evidence before the committing court, and (4) the right to confront and cross-examine adverse witnesses, unless the court specifically finds good cause for not allowing confrontation. See Gagnon v. Scarpelli, supra, 411 U.S. at 786, 93 S.Ct. at 1761-1762, 36 L.Ed.2d at 664; In re Bye, supra, 115 Cal.Rptr. at 391, 524 P.2d at 863; Ball v. Jones, supra, 43 A.D.2d at 287, 351 N.Y.S.2d at 206.
The question remains whether defendant was denied due process in the present case.
Although defendant objected at the August 4 hearing to lack of notice of his alleged misconduct, he did not repeat this objection in the September 30 proceeding. He next raised this issue in a brief filed in support of his motion in arrest of judgment. We assume, without deciding, that his failure to urge the objection in the September 30 proceeding bars him from now asserting a denial of due process because of absence of written notice of the basis of that proceeding. Cf. State v. Farmer, 234 N.W.2d 89 (Iowa 1975).
The sequence of events surrounding the evidentiary hearing issue presents a different picture. Defendant's first attorney requested the opportunity to present evidence in the August 4 proceeding, but the trial court said he did not have a right to do so. The court viewed it as a matter of grace. Counsel had no occasion to pursue the issue because the court decided to return defendant to ADAPT. However, the court did tell defendant: "When you become unacceptable to ADAPT, you will go to the penitentiary. It's like that."
When ADAPT subsequently informed the court defendant had indeed become unacceptable, the court did not order a hearing on that issue. Instead, the court ordered defendant returned for sentencing.
It was not unreasonable for defendant's first attorney to conclude, as he testified he did, that the trial court had foreclosed any idea of an evidentiary hearing regarding defendant's unacceptability to ADAPT. If defendant desired an evidentiary hearing, the attorney should have made a record to that effect during the September 30 sentencing proceeding. However, in view of the trial court's earlier indication of the futility of such effort, we do not believe the defendant should be penalized for having waited to raise the issue until his motion in arrest of judgment. See State v. Allen, 224 N.W.2d 237, 241 (Iowa 1974); State v. Miller, 204 N.W.2d 834, 841 (Iowa 1973). It was not too late then for the trial court to change its position and accord defendant a hearing if it was so inclined, but the court was not willing to do so.
The purpose of requiring a timely objection is to alert the trial court in time to permit the defect to be corrected, if the objection is good. State v. Williams, 207 N.W.2d 98, 109-110 (Iowa 1973). That purpose was served here.
Defendant's opportunity for allocution in the September 30 sentencing proceeding fell far short of an evidentiary hearing of the kind to which he was entitled. The allegations and evidence against him were not disclosed. He had been earlier warned he had no right to be heard or to present evidence. No adverse witnesses were produced.
Under this record his commitment to ADAPT was terminated without due process of law.
II. The statutory claim. Three circumstances are defined in § 204.409(2) for return to court of a defendant committed for drug treatment under its provisions. One exists when he has violated a provision of Code chapter 204. The second exists when he "has received maximum benefit from the program", and the third exists when he has recovered.
Defendant contends none of these circumstances was established in this case. No violation of chapter 204 during his stay with ADAPT was either alleged or shown. The State implicitly admitted he received *338 no benefit from the program and had not recovered from his drug dependency.
The issue of statutory interpretation is whether "maximum benefit" includes the situation where a commitment to the treatment facility is terminated because of the accused person's inability or unwillingness to cooperate in therapy. We believe it must do so.
The question is one of legislative intent. State v. Prybil, 211 N.W.2d 308, 311 (Iowa 1973). The legislature obviously did not intend that an individual who was not amenable to treatment should remain in the treatment facility. Thus, we conclude that the term "maximum benefit" was intended to include all situations in which the defendant would not benefit from further efforts at treatment in the facility, even though the result might be no benefit from the commitment.
In this manner the legislature has also established the standard for determining when a recalcitrant defendant should have his commitment to the facility terminated. It should be terminated when the trial court finds the purposes of commitment will no longer reasonably be served. The court has discretion to order the commitment initially. State v. Horton, 231 .N.W.2d 36 (Iowa 1975). It must also have discretion to terminate it when the treatment facility can do nothing further for the defendant. An allegation that a defendant has received maximum benefit from treatment includes such situations.
We find no merit in defendant's assertion that the court lacked authority to terminate his commitment.
III. The accommodation hearing claim. Defendant contends he should have been given the right to an accommodation hearing prior to sentencing because he had not been advised of his right to request such a hearing after his plea of guilty to the delivery charge. See State v. Barrett, 250 N.W.2d 31 (Iowa 1977).
The problem with this contention is that defendant did not have the right to an accommodation hearing. This offense occurred July 22, 1976. The bifurcated procedure under § 204.410, The Code, 1975, which was involved in State v. Barrett, supra, was eliminated by a statutory amendment effective July 1, 1976. Acts 66 G.A., Ch. 1245, ch. 4 § 231. Under the amendment, as in the present Code, an accommodation offense is included in a delivery charge. See § 204.410, The Code. In this case defendant pled guilty to the major charge and thereby gave up any right to be convicted only of the included offense.
He did not have the right which he claims he should have been permitted belatedly to exercise.
IV. The sentencing claim. Defendant alleges his sentence was excessive. The sentence was within statutory limits and would not be excessive unless it resulted from an abuse of discretion. State v. Noonan, 246 N.W.2d 236, 237 (Iowa 1976).
The record is not clear that the trial court recognized its discretion under § 204.409(2) in sentencing defendant. Because the sentence must be vacated for further proceedings under the statute in any event, we do not decide that issue. However, we note that a trial court does have discretion in sentencing a defendant whose commitment for treatment has been terminated. We do not intimate what the sentence should be, only that the court's discretion must be exercised. See State v. Robbins, 257 N.W.2d 63, 69-70 (Iowa 1977).
We reverse the order overruling defendant's motion in arrest of judgment and vacate the sentence. The trial court shall afford defendant a hearing upon proper notice on the issue of terminating his commitment to ADAPT in accordance with the procedures required in this opinion. If, after hearing, the court finds the commitment should be terminated, it may do so and then proceed to resentence defendant, exercising its discretion in accordance with § 204.409(2).
REVERSED AND REMANDED WITH INSTRUCTIONS.
NOTES
[1]  The court's ruling was an appealable final judgment under principles explained in State v. Gillespie, 271 N.W.2d 686 (Iowa 1978).
