
769 N.W.2d 169 (2009)
In re the DETENTION OF Gelen Kendrick SHAFFER Galen Kendrick Shaffer, Appellee.
No. 08-1358.
Supreme Court of Iowa.
July 17, 2009.
*170 Thomas J. Miller, Attorney General, Linda J. Hines and Becky Goettsch, Assistant Attorneys General, for appellant.
Mark C. Smith, State Appellate Defender, and Michael H. Adams, Assistant Public Defender, for appellee.
CADY, Justice.
In this appeal, we must decide if the district court properly dismissed the State's petition seeking the civil commitment of Galen Kendrick Shaffer as a sexually violent predator. The district court determined Shaffer was not presently confined as required by the Sexually Violent Predator Act and dismissed the petition. Upon our review, we reverse the decision of the district court and remand the case for further proceedings to determine whether Shaffer is a sexually violent predator.

I. Background Facts and Proceedings.
This case arises from a petition for the civil commitment of Galen Kendrick Shaffer *171 filed by the State under Iowa Code chapter 229A (2007)[1], the Sexually Violent Predator Act. In 1991, Shaffer was adjudicated to have committed a delinquent sexual act as a minor. Four years later, he was convicted as an adult of three counts of sexual abuse in the second degree. He was sentenced to three concurrent indeterminate terms of incarceration not to exceed twenty-five years.
Shaffer was committed to the custody of the Iowa Department of Corrections to serve his indeterminate term of incarceration. See Iowa Code § 902.3 (providing that a court sentencing a felon other than a class "A" felon to confinement "shall commit the person into the custody of the director of the Iowa department of corrections for an indeterminate term"). While Shaffer remained in the custody of the Iowa Department of Corrections, he was eligible to earn a reduction of his sentence based upon his behavior. See Iowa Code § 903A.2. The statutes governing reduction of sentences were amended multiple times during Shaffer's confinement,[2] and on numerous occasions the department calculated Shaffer's release date by applying the amendments and other factors. The last discharge date calculated by the department prior to the dispute raised in this case was July 2008. Shaffer never challenged the calculation of his discharge dates before the State filed the petition for civil commitment at issue in this appeal.[3]
The State filed the petition for civil commitment on October 9, 2007. The petition alleged Shaffer was in state custody and probable cause existed to believe he was a sexually violent predator. Shaffer was in prison in the state penitentiary at Anamosa at the time. Shaffer then filed two applications for postconviction relief. On October 19, 2007, Shaffer filed an application for postconviction relief in Jones County, where the Anamosa State Penitentiary is located. On October 24, 2007, Shaffer filed a second application for postconviction relief in Black Hawk County, where he was convicted of sexual abuse in the second degree in 1995.
The two applications for postconviction relief alleged identical grounds for relief. Shaffer alleged his sentence had expired, he was otherwise unlawfully held, and "[t]ime [was] unlawfully forfeited pursuant to procedures of Iowa Code chapter 903A." *172 Shaffer asserted his sentence was extended by application of amendments to the statute governing reduction of sentence, Iowa Code § 903A.2, in violation of the Ex Post Facto and Due Process Clauses of the federal and state constitutions. Neither application for postconviction relief explicitly addressed the State's petition for civil commitment.
The district court in Jones County held application of the amendments to section 903A.2 to Shaffer violated the Ex Post Facto Clause because the new statutory provision governing the reduction of sentences made the punishment for Shaffer's prior criminal conduct more onerous.
The district court in Black Hawk County held a probable cause hearing on the State's petition for civil commitment, together with a hearing on the application for postconviction relief. Shaffer asserted the district court had no subject matter jurisdiction to hear the State's petition for civil commitment because he was not "presently confined" under section 229A.4. He claimed he was not "presently confined" because he should have been discharged in September 2007 under the applicable version of section 903A.2, prior to the time the petition was filed.
The district court in Black Hawk County held application of the amendment to section 903A.2 to Shaffer violated Shaffer's rights under the Ex Post Facto Clause. It also held the State failed to timely file the petition for civil commitment because Shaffer should have been released under the applicable law before the State filed its petition. As a result, the district court granted summary judgment on Shaffer's application for postconviction relief and dismissed the state's petition for civil commitment.[4]
The State filed an appeal from the order by the district court dismissing its petition for civil commitment.[5] The only issue we review is whether Shaffer was presently confined under Iowa Code section 229A.4.[6]

II. Standard of Review.
The scope of review of this legal question is for errors at law. Iowa R.App. P. 6.907 (2009). We have reviewed previous constructions of the provisions of chapter 229A for corrections of errors of law. See In re Det. of Willis, 691 N.W.2d 726, 728 (Iowa 2005). To the extent Shaffer raises constitutional issues, our review is de novo. Id.


*173 III. Statutory "Presently Confined" Requirement.
The Sexually Violent Predator Act (SVP Act) plots two separate courses for the civil commitment of a sexually violent predator. See Iowa Code § 229A.4 (providing certain criteria to commence proceedings to commit "a person presently confined" and separate criteria to commence proceedings to commit "a person who has committed a recent overt act"). Only the first option is implicated in this case because the State does not allege a recent overt act other than the act constituting the basis for Shaffer's conviction for sexual abuse in the second degree. Under the first option,
If it appears that a person presently confined may be a sexually violent predator and the prosecutor's review committee has determined that the person meets the definition of a sexually violent predator, the attorney general may file a petition alleging that the person is a sexually violent predator and stating sufficient facts to support such an allegation.
Id. § 229A.4(1).
The district court held Shaffer's sentence expired under the applicable law before the State filed its petition for civil commitment, and therefore, Shaffer was not "presently confined" as required by section 229A.4 of the SVP Act. The State argues Shaffer was presently confined, whether properly or not, when it filed the petition for civil commitment.
Ultimately, the issue presented in this case requires us to interpret the statutory phrase "presently confined." Consequently, our role is to determine the intent of the legislature. State v. Sluyter, 763 N.W.2d 575, 581 (Iowa 2009). A host of rules exist to assist in this task. See Iowa Code § 4.6. In this case, the primary rule we rely upon is that statutes are interpreted consistent with the common law and with other laws pertaining to similar subjects. Id. § 4.6(4); Schaer v. Webster County, 644 N.W.2d 327, 336 (Iowa 2002).
This is not the first time we have considered whether the person named in a petition for civil commitment was "presently confined" at the time of the petition for the purposes of chapter 229A. In the case In re Detention of Gonzales, 658 N.W.2d 102 (Iowa 2003), the State petitioned for civil commitment of an individual while he was incarcerated for operating a motor vehicle without the owner's consent. Gonzales, 658 N.W.2d at 102-03. We interpreted the term "presently confined" in chapter 229A to require the confinement to be for a sexually violent offense. Id. at 104. We reasoned that a contrary construction would not be just or reasonable, in part, because it would allow the State to rely on trivial offenses to start the civil commitment process. Id. at 104-05. As a result, we dismissed the petition for civil commitment. Id. at 106.
Shaffer argues he was not confined for a sexually violent offense at the time of the State's petition, as required by Gonzales. Instead, he maintains he was held unlawfully in violation of the Ex Post Facto Clause at the time the State petitioned for civil commitment. The State acknowledges that our recent decision in State v. Iowa District Court, 759 N.W.2d 793 (Iowa 2009), resolves the ex post facto issue in Shaffer's favor, but argues Shaffer was nonetheless "presently confined" for purposes of the SVP Act.
There is no doubt Shaffer was imprisoned at the Anamosa State Penitentiary in the custody of the department of corrections on October 9, 2007, when the State filed the petition for civil commitment. He was in the custody of the department as a result of the manner the department calculated *174 the reductions of his indeterminate twenty-five year sentence. The calculations were based on the department's interpretation of two amendments to section 229A enacted after Shaffer was incarcerated.
There is likewise no dispute that the department of corrections is charged with "control, treatment, and rehabilitation of offenders committed under law to" the Anamosa State Penitentiary. Iowa Code § 904.102. Each offender committed to the custody of the department is eligible to earn a reduction of sentence as provided by statute, id. § 903A.2, and the director of the department of corrections is tasked with developing rules to implement the reduction of sentences, id. § 903A.4. The department of corrections generated an earned time report for Shaffer reflecting the number of credits earned and the amount of time remaining on his sentence. See id. § 903A.4 (requiring earned time reports). As of the date the State petitioned for civil commitment, Shaffer had not challenged the department's calculation of earned time. See id. § 822.2 (providing postconviction relief procedure for any person who claims "[t]he person's sentence has expired, or probation, parole, or conditional release has been unlawfully revoked, or the person is otherwise unlawfully held in custody or other restraint").
Those circumstances distinguish this case from the Gonzales case. Gonzales served his sentence on a sex offense, was released from custody, and was later incarcerated on separate charges. Gonzales, 658 N.W.2d at 102. Here, Shaffer has been in continuous State custody. Moreover, the State never relied on any legal basis to justify his custody other than his sexual abuse conviction. Although Shaffer's term of incarceration for this offense would have expired if his sentence had been reduced according to the applicable law, he was still confined, with no claim of bad faith, due to the sexual abuse conviction. Under the circumstances, the concerns leading to dismissal of the petition for civil commitment in Gonzales are not implicated.
We have rejected previous attempts to apply a hypertechnical definition of the phrase "presently confined." In Willis, we rejected the contention that the person named in a petition for civil commitment under the SVP Act was not presently confined at the time of the petition because he had not yet been convicted of the sexual offense for which he was being confined. 691 N.W.2d at 729. We noted, "It is only necessary that the subject be `presently confined' for a sexually violent offense." Id. We held the presently confined requirement was met even though there had been no conviction because "[t]he basis for the sheriff's custody of Willis at the time the petition was filed was the fact that he had committed a sexually violent offense." Id. It was irrelevant to the analysis that later judicial proceedings could have shown the sheriff's custody to be unlawful.
Similarly, in this case, the State confined Shaffer under a good-faith belief that the relevant statutes governing his release date required his continued confinement. Nothing in the record suggests bad faith or gamesmanship, and Shaffer never disputed the calculation of his release date prior to the time the petition was filed. The subsequent challenges to the State's calculation of Shaffer's release date and our holding in Iowa District Court do not change the historical fact that Shaffer was confined for sexual abuse in the second degree when the State petitioned for his civil commitment.
A number of familiar legal principles applicable in parallel areas of the law support our conclusion Shaffer was "presently confined." For instance, it is a fundamental *175 principle of law that, when a court has authority to make an order and jurisdiction over the subjects of the order, an order by the court must be obeyed regardless of the substantive legality of the order; and any breach of the order is subject to punishment for contempt. Lutz v. Darbyshire, 297 N.W.2d 349, 352 (Iowa 1980), overruled on other grounds by Phillips v. Iowa Dist. Ct., 380 N.W.2d 706 (Iowa 1986). Similarly, "one may be guilty of the crime of resisting arrest even if the initial arrest is illegal." Smith v. State, 542 N.W.2d 567, 569 (Iowa 1996). Likewise, we have held an inmate may not disobey a correctional officer's direct order, even when the order suffered from some defect. Id.
The relevant and unifying principle that emerges is that the ability of each of these government institutions to achieve its mission depends to some degree upon a presumption its actions are legal until proven otherwise. Likewise, the ability of other interested partiesincluding crime victims, government attorneys and agencies, and even inmates themselvesto rely on department of corrections calculations until those calculations are shown to be erroneous is essential to the efficient discharge of correctional functions. In this case, the SVP Act names the attorney general as the party responsible for petitioning for civil commitment of suspected sexually violent predators. Iowa Code § 229A.4(1). We refuse to hold the legislature intended the SVP Act to require the attorney general to second-guess the department of corrections' calculation of indeterminate sentences when the person subject to the sentence has not done so. Instead, we believe our legislature would have had these concepts in mind in enacting the statute with the "presently confined" language.
We conclude a person named in a petition for civil commitment as a sexually violent predator is "presently confined" under section 229A.4(1), even though the basis of confinement may later be found to be erroneous. This interpretation does not mean Shaffer's view would not have merit if he was knowingly and purposely confined by the department contrary to the law simply to give the State an opportunity to file a petition. In this case, however, Shaffer was confined pursuant to an unchallenged, good-faith application of the law to his sentence. The collateral attacks on the validity of that application of law and the subsequent determination the calculation was unconstitutional cannot alter the fact he was presently confined for a sexually violent offense on the date the State petitioned for civil commitment. Under the facts of this case, we hold Shaffer was "presently confined" at the time the State filed its petition for civil commitment.

IV. Conclusion.
Shaffer was presently confined as required by the SVP Act. We reverse the district court's dismissal of the petition for civil commitment and remand the case for further proceedings required by the SVP Act.
REVERSED AND REMANDED.
NOTES
[1]  All statutory references are to the 2007 Iowa Code unless noted otherwise.
[2]  At the time of Shaffer's conviction, the Iowa Code provided for "a reduction of sentence of one day for each day of good conduct of the inmate while committed." Iowa Code § 903A.2 (1995). The Code also provided "[i]n addition to the sentence reduction of one day for each day of good conduct, each inmate is eligible for an additional reduction of sentence of up to five days a month" for satisfactory participation in a work or treatment program. Id. In 2000, the Iowa Code was amended to rename good conduct time as "earned time" and to make all accrual of earned time conditional on satisfactory participation in one of five listed programs. See 2000 Iowa Acts ch. 1173, § 4. Then in 2005, section 903A.2 was amended to reflect, for the first time, the current provision requiring certain classes of inmates to complete a sex offender treatment program to become eligible for earned time. See 2005 Iowa Acts ch. 158, § 32 (codified at Iowa Code § 903A.2 (2007)).
[3]  The record suggests Shaffer had previously challenged his dismissal from a sexual offender treatment program and the concomitant cessation of reductions to his sentence. This challenge appears to be unrelated to the State's application of the amended version of the statute governing reduction of sentences. Rather, Shaffer raised the "substantive" question of whether he should have been dismissed from the treatment program under the rules of that program. His challenge did not relate to the propriety of the change in legal consequences of the dismissal resulting from the amendments to the statutes dealing with reduction of sentences.
[4]  The following day, the district court filed two supplemental orders. In the first supplemental order, the court found probable cause to believe Shaffer is a sexually violent predator. In the second supplemental order, the court stayed any release of Shaffer from State custody pending appeal.
[5]  The State separately appealed the summary judgment on Shaffer's Black Hawk County application for postconviction relief. We do not address that appeal here.
[6]  The State has also argued its application of section 903A.2 as amended is not an ex post facto violation. On January 23, 2009 (during the pendency of this appeal), this court addressed an identical ex post facto issue regarding section 903A.2 in State v. Iowa District Court, 759 N.W.2d 793 (Iowa 2009). We held application of the amendments to section 903A.2 to offenders already sentenced violates the Ex Post Facto Clause of the United States Constitution. Iowa Dist. Ct., 759 N.W.2d at 802. As a result of that opinion, the State filed a motion to amend its brief in this case to remove its argument regarding the ex post facto application of amendments to section 903A.2. This court denied the motion and instead interpreted the motion as a waiver of any district court error on the ex post facto issue by the State. Following our resolution of the ex post facto issue in Iowa District Court, the State also voluntarily dismissed its separate appeals in Shaffer's two postconviction relief actions.
