
117 Wis.2d 579 (1984)
345 N.W.2d 413
STATE of Wisconsin, Plaintiff-Respondent,
v.
Emery WALKER, Defendant-Appellant-Petitioner.[]
No. 83-549-CR.
Supreme Court of Wisconsin.
Argued February 29, 1984.
Decided March 27, 1984.
For the defendant-appellant-petitioner there were briefs by Jack E. Schairer and William J. Tyroler, assistant state public defenders, and oral argument by Mr. Schairer.
For the plaintiff-respondent the cause was argued by Stephen W. Kleinmaier, assistant attorney general, with *580 whom on the brief was Bronson C. La Follette, attorney general.
WILLIAM G. CALLOW, J.
This is a review of an order of the court of appeals which vacated a sentence imposed on a conviction for injury by conduct regardless of life, and remanded the cause for resentencing by the trial court. The judgment of conviction and the sentence were entered by the Kenosha county circuit court, Judge William U. Zievers. We reverse the order of the court of appeals.
The issue presented on appeal is whether the court of appeals erred in ordering a resentencing when the sentencing procedure used by the trial judge did not comport with sec. 973.155, Stats.[1]
On March 2, 1978, a judgment of conviction was entered, finding the defendant, Emery Walker, guilty of attempted first-degree murder. In Walker v. State, 99 Wis. 2d 687, 299 N.W.2d 861 (1981), this court affirmed the *581 decision of the court of appeals which reversed the defendant's conviction and remanded the matter for a new trial. On March 6, 1981, the defendant entered a plea of no contest to a lesser charge of injury by conduct regardless of life, based upon the same acts which led to the first-degree murder conviction. A judgment of conviction was entered, and the court placed the defendant on probation for a period of five years. Subsequently, the defendant violated the terms of probation, and his probation was revoked October 4, 1982.
On October 21, 1982, the defendant appeared before Judge William U. Zievers for resentencing. At the time of resentencing, the defendant was entitled to three years and two months of credit for time served. In preliminary remarks at the sentencing hearing, Judge Zievers observed:
". . . [T]he court further being aware of the fact that the defendant had previously spent I believe approximately 3 years in prison on an earlier charge which was the subject of a reversal and the file having been consummated with a plea to the amended charge under Section 940.23. Thus, the defendant's exposure there would appear to be 10 years in prison with credit for time previously served obviously being available to him."
In imposing a "three-year" sentence, Judge Zievers stated:
". . . In imposing this sentence which is less than the maximum, the court has taken into consideration the fact that the defendant has served three years and almost 2 months on the previous felony charge in 1964 C and that having been taken into consideration there will be no credit for time previously served." (Emphasis added.)
At the conclusion of the proceedings, Judge Zievers further stated:
"Once again in this case . . . the court has not sentenced the defendant to the maximum and has taken into *582 consideration the time spent in custody . . . and so that there will be no credit for time served." (Emphasis added.)
The defendant filed a postconviction motion requesting that credit for time served be subtracted from his sentence. After a hearing held March 1, 1983, Judge Zievers on March 4, 1983, issued a decision and order denying the defendant's postconviction motion. In its decision, the court stated:
". . . [It] is the clear intent of the Court that the defendant be sentenced to these additional years on the new charge [injury by conduct regardless of life], the time already spent in confinement on the old charge [attempted first-degree murder] having been duly taken into consideration." (Emphasis added.)
The defendant filed a motion for reconsideration, which was dismissed by the court March 15, 1983. In its decision and order dismissing the motion for reconsideration, the court noted that, in its sentencing and subsequent decisions, it had taken into account North Carolina v. Pearce, 395 U.S. 711 (1969), which requires that credit for time served be given at sentencing after a new trial.
The defendant appealed to the court of appeals, moving for summary reversal on the ground that the trial court erred in not granting credit for time served against the sentence imposed. The court of appeals determined that the trial court had not followed the procedures mandated by sec. 973.155, Stats., and, therefore, that the sentence was unlawful. The court concluded that the proper remedy was resentencing by the trial court. The court vacated the sentence and remanded the case for resentencing in accordance with sec. 973.155. The defendant petitioned this court for review of the court of appeals' order. We granted the petition for review on October 11, 1983.
*583 Section 973.155, Stats., provides that a defendant is entitled to credit for all days spent in custody in connection with the course of conduct for which the sentence was imposed.[2]See also Wis. J ICriminal SM-34A. Under this provision, the defendant was entitled to credit for the three years and two months he served in connection with the attempted first-degree murder conviction. This time was to be credited against any sentence imposed on the lesser charge of injury by conduct regardless of life, to which the defendant pled no contest.
In Klimas v. State, 75 Wis. 2d 244, 252, 249 N.W.2d 285 (1977), we developed a procedure for applying credit for time served against the sentence. The trial court was first to determine an appropriate sentence, then determine the time spent in custody, and, finally, credit that time against the sentence imposed. This procedure was subsequently codified in sec. 973.155(2), Stats. The state concedes that the defendant was entitled to credit for the time served on his original conviction and that the trial court did not follow the proper procedure in sentencing the defendant on his second conviction. Thus, the sole question is what remedy the defendant is entitled to in order to correct the sentence.
[1]
In previous cases, we have held that resentencing is the appropriate remedy where the sentence was "legally impermissible" or "unlawful," see State v. Upchurch, 101 Wis. 2d 329, 336, 305 N.W.2d 57 (1981), or where the sentence "is not in accord with the law," see Grobarchik *584 v. State, 102 Wis. 2d 461, 470, 307 N.W.2d 170 (1981). We have also recognized that resentencing is appropriate when the appellate court would have to infer what sentence the trial court would have imposed had it proceeded on a proper understanding of the applicable law. See Robinson v. State, 102 Wis. 2d 343, 356, 306 N.W.2d 668 (1981). On the other hand, when it is clear what the trial court intended to do when it imposed an otherwise improper sentence, we have modified the sentence to carry out the intent of the trial court while bringing the sentence into accordance with the applicable law. See Struzik v. State, 90 Wis. 2d 357, 279 N.W.2d 922 (1979).
[2]
The record supports a presumption that the trial judge was aware of the law of this state that defendants are entitled to credit for time served. We also presume that the trial judge intended to impose a lawful sentence. We conclude that, although the trial judge failed to follow the proper procedure in imposing the sentence, the underlying sentence was valid. The appropriate remedy for correcting the sentence imposed in this case is to modify it to bring it into conformity with the requirements of sec. 973.155, Stats.
The trial judge stated that in imposing the sentence he was required to and had "taken into consideration" the time previously served. The trial judge apparently decided that a sentence of six years and two months was appropriate for the charge of injury by conduct regardless of life; the judge then, without explicitly stating, subtracted the amount of time served to reach the three-year sentence which was actually imposed. When the trial judge represented that no credit was to be given for time served, we assume he only meant to imply that he had already subtracted that amount when he announced the three-year sentence. If that time had already been subtracted, it would have been accurate to state that no *585 further time-served credit would be given because otherwise it would amount to a double credit.[3]
From this record, we conclude that the trial judge intended to impose a sentence of six years and two months on the charge of injury by conduct regardless of life. In his comments at the sentencing hearing, the trial judge repeatedly noted the serious nature of the crime and also concluded that the defendant had shown by his actions that his previous incarceration had not deterred him from further criminality. Thus, we may presume the trial judge intended that the defendant be subject to further incarceration because of the gravity of the offense and the defendant's behavior during probation. A sentence of six years and two months was reasonable under these circumstances. To accept the defendant's argument that the trial judge intended only a three-year sentence, which would be nullified by the time-served credit, would be entirely inconsistent with the trial judge's intention revealed at sentencing. We conclude that, although the manner in which the trial judge enunciated the sentence was inartful and did not comport with the procedure mandated by sec. 973.155, Stats., the intended sentence itself was valid and did not constitute an abuse of the trial judge's sentencing discretion.
*586 We caution, however, that the statutory procedure should be followed. Under this procedure trial judges are first to determine and impose an appropriate sentence independently of any time previously served. Only then should time served be determined and become relevant to the final sentence imposed on the conviction. The time previously served should not be a factor in the exercise of sentencing discretion because such credit is a constitutional right of the defendant which exists independently of what the trial judge determines to be appropriate punishment for a given offense. That is the reason why the statutory procedure first requires a determination of the appropriate sentence, then a determination of the time served, and, finally, a credit for time served against the sentence.
The order of the court of appeals vacating the sentence and remanding the cause for resentencing is reversed. The sentence is modified by imposing a sentence of six years and two months, to which shall be credited three years and two months.
By the Court.The order of the court of appeals is reversed; judgment modified.
NOTES
[]  Motion for reconsideration denied.
[1]  Section 973.155, Stats., provides in relevant part:

"Sentence credit. (1)(a) A convicted offender shall be given credit toward the service of his or her sentence for all days spent in custody in connection with the course of conduct for which sentence was imposed. As used in this subsection, "actual days spent in custody" includes, without limitation by enumeration, confinement related to an offense for which the offender is ultimately sentenced, or for any other sentence arising out of the same course of conduct, which occurs:
1. While the offender is awaiting trial;
2. While the offender is being tried; and
3. While the offender is awaiting imposition of sentence after trial.
". . .
"(2) After the imposition of sentence, the court shall make and enter a specific finding of the number of days for which sentence credit is to be granted, which finding shall be included in the judgment of conviction. In the case of revocation of probation or parole, the department shall make such a finding which shall be included in the revocation order."
See also sec. 973.04.
[2]  The statute embodies the rule announced by the United States Supreme Court in North Carolina v. Pearce, 395 U.S. 711, 718-19 (1969), ". . . that the constitutional guarantee against multiple punishments for the same offense absolutely requires that punishment already exacted must be fully `credited' and imposing sentence upon a new conviction for the same offense." (Footnote omitted.) See also Struzik v. State, 90 Wis. 2d 357, 367, 279 N.W.2d 922 (1979).
[3]  The defendant urges us to credit the time-served credit of three years and two months against the three-year sentence which the trial judge imposed. We decline to follow this suggestion because "[s]uch a rule would tend to make the sentencing proceeding a game wherein a misstatement by the trial judge would result in a windfall to the defendant." State v. Upchurch, 101 Wis. 2d 329, 336, 305 N.W.2d 57 (1981). We do not think that the trial judge's failure to follow the statutory procedures to the letter should be the basis, in effect, to give the defendant a double credit for time served. Further, given the trial judge's comments at the sentencing hearing, we do not believe that wiping out the three-year sentence with time-served credit would be consistent with the trial judge's intended punishment.
