
753 N.W.2d 562 (2008)
STATE of Iowa, Appellant,
v.
Lee Andrew SMITH, Appellee.
No. 07-0687.
Supreme Court of Iowa.
July 25, 2008.
Thomas J. Miller, Attorney General, Karen Doland, Assistant Attorney General, Thomas J. Ferguson, County Attorney, and Linda Fangman, Assistant County Attorney, for appellant.
John J. Sullivan of Sullivan Law Office, Oelwein, for appellee.
*563 WIGGINS, Justice.
In this case we must decide whether a defendant who waived his right to file a motion in arrest of judgment at his initial sentencing, and whom the district court ordered to be resentenced because his original sentence was illegal, can file a motion in arrest of judgment before he is resentenced. Because we find the defendant cannot file a motion in arrest of judgment before resentencing under these circumstances, we reverse the judgment of the district court granting the defendant a new trial and remand the case for resentencing.

I. Background Facts and Proceedings.
The State charged Lee Smith with first-degree burglary, third-degree sexual abuse as a habitual offender, and assault causing injury as a habitual offender. The case proceeded to trial on June 27, 2006. At some point during the testimony of the State's first witness, Smith negotiated a plea bargain. Smith pled guilty to all three counts under a sentencing recommendation for twenty-five years on count one (burglary), fifteen years on count two (sexual abuse), and fifteen years on count three (assault), with counts two and three running concurrent to each other but consecutive to count one, for a total of forty years.
In the required colloquy, the judge informed Smith he would have to take a batterer's education class, register as a sex offender, and pay a civil penalty. The judge failed to inform Smith that under Iowa Code section 903B.1 (Supp.2005) he would be subject to mandatory lifetime supervision by the department of corrections as a result of his guilty plea to the habitual offender sexual assault charge. The district court accepted Smith's plea.
Smith requested immediate sentencing. The judge explained to Smith that by accepting immediate sentencing Smith would waive his right to file a motion in arrest of judgment. The colloquy between the judge and Smith indicated Smith understood he was waiving that right. The court then sentenced Smith to the recommended sentence without sentencing him to mandatory lifetime supervision.
On October 31, the chief judge of the first judicial district entered an order finding Smith's sentence did not comply with section 903B.1. On November 15, the district court entered an order setting aside Smith's first sentence and scheduling a resentencing hearing for December 18. At the December 18 hearing, Smith requested to withdraw his guilty plea on the basis that the court did not inform him of the mandatory lifetime supervision requirement. The judge continued the resentencing hearing to January 16, 2007. On January 11, five days before the resentencing hearing, Smith filed a motion in arrest of judgment and an application to withdraw his guilty plea.
The district court entered an order granting Smith a new trial. The court held it could correct an illegal sentence at any time and Smith's sentence was illegal because it did not include the mandatory lifetime supervision requirement under section 903B.1. Additionally, the court held that Smith was not informed of a direct consequence of his plea, the mandatory lifetime supervision; thus, his plea was unknowing. Finally, the court held the improper plea invalidated the entire agreement, not just the plea to sexual assault, because a plea agreement is akin to a contract; therefore, it cannot be partitioned.
The State appeals.


*564 II. Issue.
The only issue we need to decide is whether the district court should have considered Smith's motion in arrest of judgment prior to the resentencing.

III. Scope of Review.
We review a district court's grant or denial of a motion in arrest of judgment and a motion to withdraw a plea for abuse of discretion. State v. Myers, 653 N.W.2d 574, 581 (Iowa 2002) (motion in arrest of judgment); State v. Blum, 560 N.W.2d 7, 9 (Iowa 1997) (motion to withdraw plea). An abuse of discretion will only be found where the trial court's discretion was exercised on clearly untenable or unreasonable grounds. State v. Craig, 562 N.W.2d 633, 634 (Iowa 1997). A ruling is untenable when the court bases it on an erroneous application of law. Graber v. City of Ankeny, 616 N.W.2d 633, 638 (Iowa 2000).

IV. Analysis.
The State contends the district court improperly considered Smith's motion in arrest of judgment because he waived his right to file the motion at the original sentencing. In State v. Peterson, 327 N.W.2d 735 (Iowa 1982), we found a sentence to be illegal and remanded the case for resentencing, instructing the district court to allow the defendant to file a motion in arrest of judgment prior to the resentencing. 327 N.W.2d at 738-39. However, in Peterson, neither party raised, nor did this court consider, whether the defendant's initial waiver of his right to file a motion in arrest of judgment would preclude the filing of a new motion in arrest of judgment prior to resentencing.
Our criminal rules of procedure require the court to sentence a defendant within a reasonable time after entry of a guilty plea, but not less than fifteen days after the defendant enters the plea. Iowa R.Crim. P. 2.23(1). The rules also require a defendant to file a motion in arrest of judgment no later than forty-five days after the plea, but in any case no later than five days before the sentencing. Id. r. 2.24(3)(b). Smith claims his motion in arrest of judgment was timely because he filed it no later than five days before the resentencing. We disagree.
We must construe the time limits set for sentencing in conjunction with the time limits set for filing a motion in arrest of judgment. See Niles v. Iowa Dist. Ct., 683 N.W.2d 539, 541 (Iowa 2004) (holding courts are obliged to consider a challenged statute in its entirety and in pari materia with other pertinent statutes). Construing these two rules together, we find if the date of sentencing is set for more than fifty days after the plea, the maximum time a defendant has to file the motion in arrest of judgment is forty-five days from the plea. On the other hand, if the court sets the date of sentencing less than fifty days after the plea, the maximum time a defendant has to file the motion is no later than five days before the sentencing. Id. The not-later-than-five-days time limitation has no application to a resentencing. Consequently, Smith's voluntary waiver of his right to file a motion in arrest of judgment continues to apply at the time of his resentencing. Therefore, it was clearly erroneous for the court to consider Smith's motion in arrest of judgment, and the court abused its discretion by considering the motion.
When a defendant claims a plea was not made knowingly and voluntarily because the court failed to disclose the maximum penalty, but the defendant failed to file a motion in arrest of judgment, we have decided the proper remedy is for the defendant to raise this issue on postconviction relief. State v. Bearse, 748 N.W.2d *565 211, 219 (Iowa 2008); State v. Straw, 709 N.W.2d 128, 138 (Iowa 2006). Thus, because the district court improperly considered the motion in arrest of judgment, Smith's avenue for relief is a postconviction-relief proceeding. Id.

V. Disposition.
Because Smith waived his right to file a motion in arrest of judgment, the district court improperly considered his motion when it entered an order granting him a new trial. Accordingly, we reverse the judgment of the district court. We remand the case for the sole purpose of resentencing Smith. After resentencing, Smith may bring an action for postconviction relief challenging his guilty plea.
REVERSED AND CASE REMANDED WITH INSTRUCTIONS.
All justices concur except BAKER, J., who takes no part.
