
    STATE of Missouri, ex rel. Jeremiah W. (Jay) NIXON, Attorney General, Relator, v. The Honorable Robert H. DIERKER, Jr., Circuit Judge of the Circuit Court of St. Louis City and Mariano V. Favazza, Circuit Clerk, St. Louis City, Respondents.
    No. ED 77708.
    Missouri Court of Appeals, Eastern District, Division Seven.
    July 25, 2000.
    
      Jeremiah W. (Jay) Nixon, Atty. Gen., Cassandra K. Dolgin, Asst. Atty. Gen., Jefferson City, for appellant.
    William Gavras, St. Louis, for respondent.
   WILLIAM H. CRANDALL, Jr., Presiding Judge.

This is an original proceeding in certiorari to review the issuance of a writ of habeas corpus by the Circuit Court of the City of St. Louis. We quash the writ.

On May 2, 1988, Marvin C. Logan pleaded guilty to two counts of assault in the first degree. At the plea hearing, the prosecutor presented the following recommendation to the sentencing court:

We are recommending on Count I Mr. Logan be sentenced to [a] seven year[s] period of imprisonment, Missouri Department of Corrections. We are recommending that sentence be served concurrently with the six year[s] sentence he is now doing, and we are allowing him the benefit of all jail-time that he accumulated with regard to the previous sentence....

On Count I, the court sentenced Logan to a term of imprisonment of seven years, to be served concurrent with a six year sentence he was serving on a previous offense of receiving stolen property for which he was sentenced in November 1986. Logan was to be given credit for all time served on that previous offense. On Count II, the court sentenced Logan to a term of imprisonment of seven years, to run consecutive to the sentence imposed on Count I. Execution of sentence on Count II was suspended and Logan was placed on five years probation. Logan received no jail time credit on that count.

When the Missouri Department of Corrections (hereinafter DOC) initially calculated Logan’s sentence, it complied with the court’s sentence: The seven year sentence on Count I began on August 6, 1986 and expired on August 5, 1993, and the seven year sentence on Count II began on July 12,1991 and expired on July 11, 1998. On February 7, 1992, the court revoked Logan’s probation and ordered him committed to the DOC to serve the seven year sentence on Count II, with credit applied thereto for seven months’ probation. On August 5,1993, Logan received an “Official Discharge” on Count I. As to Count II, Logan was placed on parole under the supervision of the Missouri Board of Probation and Parole on November 22, 1995. In July 1998, when Logan violated his parole, he was returned to custody. In May 1999, the DOC recalculated the sentence credit received on Count I and determined that the seven year sentence on Count I did not begin until May 2, 1988 and expired on May 1, 1995, and that the seven year sentence on Count II began on October 1, 1994 and expired on September 30, 2001.

On January 12, 2000, Logan was placed on parole on the condition that he successfully complete a work release program. Logan filed a petition for writ of habeas corpus, alleging that he was entitled to jail time credit for the time served on the six year sentence for receiving stolen property and to be released from the custody of the DOC. The habeas court granted the writ and entered an order to show cause why Logan should not be discharged from custody. Later the habeas court ordered Logan released on his own recognizance.

Although the habeas court agreed that the sentencing court improperly credited Logan with time served on the previous offense, the habeas court stated that the “defect was in the form in which the sentencing court adopted the bargain, not in its substance.” The habeas court vacated and set aside the May 1988 judgment and sentence and remanded the cause to the Circuit Court of I . Louis County for purposes of amending the sentence and judgment “to reflect a sentence of five years and three months on said count I.” The attorney general then filed a petition for writ of certiorari seeking review of the court’s grant of habeas corpus relief.

Initially, we address the issue of whether habeas corpus was an appropriate remedy in this case. “Any person restrained of liberty within this state may petition for a writ of habeas corpus to inquire into the cause of such restraint.” Rule 91.01; see also section 532.010, RSMo (1994). Rule 91 proceedings are limited to determining the facial validity of confinement. Brown v. Gammon, 947 S.W.2d 437, 440 (Mo.App. W.D.1997). Under the statutes that have codified the common law writ, the “facial validity” of confinement is determined on the basis of the entire record of the proceeding in question. Id. Habeas corpus is also available in cases where circumstances are so rare and exceptional that a manifest injustice would result in the absence of habeas corpus relief. Id. Because Logan was restrained of his liberty within this state and was inquiring into the cause of his restraint, a petition for a writ of habeas corpus was appropriate in this case. See 91.01(b)

The attorney general contends the habe-as court was without jurisdiction to order specific performance of a plea agreement that improperly included an award of jail time credit. The attorney general argues that pursuant to section 558.031, RSMo (1994), the sheriff and the DOC, not the sentencing court, were charged with the duty of determining jail time credit and such credit could not be granted for time served on an unrelated offense. He argues that Logan should be remanded to custody and given the opportunity to withdraw his plea of guilty under Rule 29.07(d).

We agree that under section 558.031 it was improper for the sentencing court to award Logan jail time credit. First, the award of jail time credit was not a matter of discretion for the sentencing court, but was a matter for the DOC. See State ex rel. Jones v. Cooksey, 830 S.W.2d 421, 424 (Mo. banc 1992). The discretion of the sentencing court is solely for the purpose of suiting the punishment to the crime. Id. We agree that it was improper for the sentencing court to grant Logan jail time credit for the reason that the May 1988 sentence for which he sought jail time credit was unrelated to the prior conviction of November 1986. Jail time credit cannot be granted for time served on an unrelated offense. See State ex rel. Lightfoot v. Schriro, 927 S.W.2d 467 (Mo.App. W.D. 1996); see also State ex rel. Blackwell v. Sanders, 615 S.W.2d 467 (Mo.App. E.D. 1981) (court refused to give the defendant credit for jail time served on a concurrent sentence before the defendant was even arrested on the second charge).

Recognizing that it was improper for the sentencing court to grant jail time credit, the habeas court nevertheless determined that the plea agreement was not illegal or against public policy. The habe-as court distinguished the present case from cases holding that jail time credit cannot be awarded for time served on an unrelated offense on the basis of “the unequivocal evidence of the sentencing court’s intent.” The habeas court found that the parties to the plea agreement as well as the sentencing court intended to grant Logan jail time credit and that it was “the form of the judgment that was defective, not the substance of the agreement.” As such, the habeas court remanded to the sentencing court to correct the sentence so that it would “reflect a sentence of five years and three months” on Count I.

The attorney general argues the habeas court was without jurisdiction to award jail time credit because the sentencing court was without jurisdiction to do so. He cites to Cooksey, 830 S.W.2d at 424, for the proposition that the habeas court cannot give effect to an agreement that the sentencing court cannot enforce. However, as the habeas court found, it was only the way in which the sentencing court attempted to enforce the plea agreement, not the plea agreement itself, which was improper. The attorney general even concedes the sentencing court had the authority to sentence Logan to coincide with the intent of the parties to the plea agreement. In particular, the attorney general stated, “Thus if the sentencing court believed a sentence of five and one-half (5 1/2) years was appropriate - also falling within the applicable sentencing range for a class B felony - rather than seven (7) years, then the sentence should have been imposed accordingly.”

The salient issue is whether the habeas court can order the sentence amended. The attorney general cites no authority, and we can find none, supporting the contention that the habeas court was without jurisdiction to order the amendment of the sentence to reflect the intention not only of the parties but also of the sentencing court. When the habeas court remanded the case to the sentencing court with instructions to amend the sentence, the ha-beas court gave effect to the intent of the parties that Logan only serve a certain amount of time. The fact that the sentencing court improperly calculated the sentence anticipated by the parties does not render the habeas court incapable of fashioning a remedy to sentence Logan in conformity with the intention of the parties. The habeas court acted within its jurisdiction in ordering the sentence be amended. Point denied.

In his second point, the attorney general contends the habeas court improperly released Logan on his own recognizance pending resolution of the petition for writ of habeas corpus. In view of our holding under point one, this point is rendered moot.

Writ of Certiorari is quashed.

GARY M. GAERTNER, J., and LAWRENCE E. MOONEY, J., concur. 
      
      . When a writ of certiorari is applied for by the attorney general, the writ issues as a matter of course and of right. State ex rel. Shartel v. Skinker, 25 S.W.2d 472, 475 (1930).
     
      
      . Section 558.031.1 provides in pertinent part:
      1. A person convicted of a crime in this state shall receive as credit toward service of a sentence of imprisonment all time spent by him in prison or jail both while awaiting trial for such crime and while pending transfer after conviction to the department of correction or the place of confinement to which he was sentenced. Time required by law to be credited upon some other sentence shall be applied to that sentence alone, except that (1) Time spent in jail or prison awaiting trial for an offense because of a detainer for such offense shall be credited toward service of a sentence of imprisonment for that offense even though the person was confined awaiting trial for some unrelated bailable offense; and
      (2) Credit for jail or prison time shall be applied to each sentence if they are concurrent.
     
      
      . The Cooksey court held that section 558.031 contemplates an administrative and not a judicial determination for the jail time to be credited, with no sharing of jurisdiction between the two branches of government. Co-oksey, 830 S.W.2d at 425.
     
      
      . The judgment on the habeas read in pertinent part:
      ORDERED, ADJUDGED AND DECREED that the petition for writ of habeas corpus is granted, and the petitioner is ordered discharged forthwith from Respondent's custody; and it is
      FURTHER ORDERED ADJUDGED AND DECREED that the judgement and sentence in the Circuit Court of St. Louis County, State of Missouri v. Marvin C. Logan, No. 570563, dated May 2, 1988, is vacated and set aside as to count I only, and this matter is remanded to the Circuit Court of St. Louis County for purposes of amending said sentence and judgement to reflect a sentence of five years and three months on said count I....
     