Larry Phillips, a detained person under the Involuntary Civil Commitment of Sexually Violent Predators Act1 (the Act) who is currently awaiting trial on the commitment petition, seeks a writ of prohibition to prevent the circuit court of Collier County from conducting further proceedings on the commitment petition. He asserts that the circuit court does not have jurisdiction to adjudicate the commitment petition filed under the Act because he was not in lawful custody at the time that proceedings under the Act were commenced. We agree that Phillips is entitled to relief on this basis.2
The facts of the case are not in dispute. In February 1990 Phillips was arrested on a fugitive warrant in Georgia and extradited to Collier County where he was charged with three counts of committing a lewd and lascivious assault. After posting bond in Florida, Phillips was returned to Georgia for prosecution of a separate offense. In July 1990 a Georgia court sentenced Phillips to three years in prison followed by seventeen years of probation for that offense. Phillips was paroled in March 1992 and returned to Florida to resolve the Collier County case.
In April 1992 the Collier County circuit court sentenced Phillips to two years in prison followed by ten years of probation. The court awarded Phillips two years of credit for the time he had served in Georgia prior to his return to Florida. This effectively erased the two-year prison sentence, and Phillips was processed in and out of the Florida Department of Corrections (DOC) on the same day that he was sentenced. Phillips thereafter returned to Georgia to serve both his Georgia and Florida probationary terms.
Less than two years later, Phillips violated both his Georgia probation and his Florida probation by committing a new law offense in Georgia. A Georgia court revoked his probation and sentenced him to prison. In January 2004 Phillips was paroled from prison in Georgia and extradited to Florida to face the violation of probation charge in Collier County. Phillips admitted to violating his Florida probation, and the court sentenced him to 5.5 years in prison with 177 days of jail credit. Less than a year later, Phillips filed a motion to correct illegal sentence pursuant to Florida Rule of Criminal Procedure 8.800(a). Phillips requested that a Florida postcon-viction court award him credit against his prison sentence for the two years of credit for time served in Georgia that the Florida *953court had awarded in 1992. In September 2005 the postconviction court granted the motion and ordered the DOC to award Phillips the original jail and prison credit in addition to the credit for the 177 days he spent in custody prior to the revocation of his probation.
On December 6, 2005, Phillips was released from the DOC and was transferred to the Florida Civil Commitment Center pursuant to section 394.9135(1), Florida Statutes (2005).3 The Department of Children and Family Services placed a seventy-two hour hold on Phillips and began its evaluation to determine whether he met the criteria for commitment as a sexually violent predator under the Act.4 The multidisciplinary team timely recommended civil commitment to the state attorney, who filed a commitment petition.
In December 2008 the Florida Supreme Court issued its decision in Lañmore v. State, 2 So.3d 101, 105 (Fla.2008), in which it held a person must be in lawful custody when commitment proceedings are initiated for the circuit court to have jurisdiction to adjudicate a commitment petition under the Act. In June 2009 Phillips, who was still in custody but had not been to trial, filed a motion to dismiss the commitment petition in the circuit court. Phillips argued that he was not in lawful custody at the time commitment proceedings were initiated on December 6, 2005, because his sentence had expired on August 31, 2005, based on the postconviction court’s determination of entitlement to two years of prison credit against Phillips’ sentence of 5.5 years. Phillips relied on an affidavit executed by a DOC administrator which stated that, with the application of the prior prison and jail credit, Phillips’ sentence expired on August 31, 2005. The DOC included the award of 420 days of basic gain time and 234 days of incentive gain time in making this calculation.5
The circuit court denied the motion to dismiss based on its determination that Phillips was in lawful custody when commitment proceedings were initiated because “[t]he time period from August 31, 2005 to December 6, 2005 was well within the legal term of [Phillips’] sentence of 5 1/2 years.” Phillips then filed this petition for writ of prohibition contending that because his sentence legally expired on August 31, 2005, he was not in lawful custody when commitment proceedings were initiated in December 2005. Phillips contends that, under Larimore, the circuit court is without jurisdiction to adjudicate the commitment petition.
Larimore involved a guilty plea to lewd and lascivious acts on a child in two separate cases in 1991. 2 So.3d at 104. Lari-more was sentenced to fifteen years in prison in one case followed by five years of probation in the second case. He was released from prison in 1998 due to a gain *954time award, and he began serving his probation. The court revoked Larimore’s probation in February 2000 and sentenced him to five years in prison.
In August 2002 the First District Court of Appeal determined that Larimore was entitled, pursuant to Tripp v. State, 622 So.2d 941 (Fla.1993), to credit against the five-year prison sentence for the time served on the fifteen-year sentence imposed in the first case, including actual prison time and gain time. Larimore, 2 So.3d at 104. The award of credit would have effectively erased the five-year sentence imposed for the violation of probation, but the DOC forfeited 2830 days of gain time Larimore had earned on his fifteen-year prison sentence. Id.
In November 2004, while Larimore was in prison, the State filed a petition for involuntary civil commitment pursuant to the Act. Less than one month later, the First District held that Larimore was entitled to immediate release from custody because the DOC’s forfeiture of his gain time was unauthorized. Id. (citing Larimore v. Fla. Dep’t of Corr., 910 So.2d 847 (Fla. 1st DCA 2004)). Larimore then filed a motion to dismiss the commitment petition on the ground that he was not in lawful custody on the effective date of the Act. After the circuit court denied his motion, he filed a petition for writ of prohibition in the First District to prevent further proceedings against him under the Act. The First District denied the petition. 2 So.3d at 104 (citing Larimore v. State, 917 So.2d 354, 355 (Fla. 1st DCA 2005)).
On review of the denial of Larimore’s petition for writ of prohibition, the supreme court held that Larimore was entitled to release because he “was not in legal custody when initial steps were taken to initiate civil commitment proceedings against him.” Id. at 117. The court noted that it had previously construed the term “custody” to mean “lawful custody” in State v. Atkinson, 831 So.2d 172, 174 (Fla. 2002), in which it held that the Act was not applicable to individuals who were not in lawful custody on its effective date. Larimore, 2 So.3d at 115. The court explained that
interpreting the Jimmy Ryce Act as not requiring lawful custody for individuals who had been incarcerated at some point after the effective date of the Act but are not in lawful custody when commitment proceedings are initiated would be contrary not only to the overall intent of the Act but “would be contrary to the basic tenets of fairness and due process.”
Id. (quoting Atkinson, 831 So.2d at 174).
This court recently applied Larimore under circumstances similar to those in this case. See Bishop v. Sheldon, 68 So.3d 259 (Fla. 2d DCA 2010). In Bishop the petitioner’s original sentence had been imposed pursuant to sentencing guidelines which were subsequently declared illegal by the supreme court. Id. at 952. The petitioner’s sentence was corrected by a postconviction court, and Bishop was entitled to immediate release because his sentence had expired. However, the petitioner was not released, and the State filed a petition for commitment under the Act. The petitioner sought a writ of habeas corpus in this court arguing that, under Larimore, the Act did not apply to him because he was not in lawful custody at the time commitment proceedings were initiated. Id. at 952-53. This court agreed that Larimore applied but transferred the case to the circuit court to resolve factual disputes over whether the petitioner was in lawful custody when commitment proceedings were initiated. Id. at 955.
This case requires a similar legal analysis but does not involve any disputed facts. Under Larimore, Phillips cannot be *955committed pursuant to the Act if he was not in lawful custody when the State initiated commitment proceedings. Phillips’ prison sentence of 5.5 years for the violation of his probation was illegal because the court failed to award prior jail and prison credit. See Haines v. State, 851 So.2d 831, 832 (Fla. 1st DCA 2003). After the postconviction court determined that the prior prison and jail credits should be applied to correct the illegal sentence, the DOC recalculated Phillips’ sentence and found that it had expired as of August 31, 2005. Thus, Phillips was not in lawful custody when the State initiated commitment proceedings in December 2005. Cf. Atkinson, 831 So.2d at 174 (holding that defendant who was resentenced because his prior sentence had been imposed pursuant to unconstitutional sentencing guidelines was not in lawful custody when his sentence expired).
We recognize that section 394.9135 provides a procedure for the DOC to initiate commitment proceedings under the Act when the release of an inmate convicted of a qualifying offense “becomes immediate for any reason.” However, this “‘safety valve’” does not apply because lawful custody is required before the State may initiate commitment proceedings. Larimore, 2 So.3d at 105, 117 (quoting Gordon v. Regier, 839 So.2d 715, 719 (Fla. 2d DCA 2003)). Thus, even though Phillips’ release became immediate upon his resentencing by the postconviction court, section 394.9135 was inapplicable. Id.
In its response to Phillips’ petition the State argues that Phillips’ reliance on Lar-imore is misplaced based on a footnote in Larimore in which the court stated as follows:
In this case, Larimore’s entire resen-tencing was unlawful. Thus, we do not reach the question of whether section 394.9135, Florida Statutes, would allow the State to take steps to initiate a commitment proceeding against a person who while in lawful custody obtains an order for immediate release for any reason. That issue is not before us.
2 So.3d at 117 n. 8. The State claims that Phillips was in lawful custody because his sentence for the violation of probation was legal except that the gain time award was “incorrect.” This argument is specious because the petitioner in Larimore was entitled to immediate release due to a misapplication of gain time. See also Madison v. State, 27 So.3d 61, 63 (Fla. 1st DCA 2.009) (relying on Larimore to remand for the circuit court to consider gain time and other credits in determining whether Madison was in lawful custody at the time commitment proceedings were initiated).
The State alternatively argues that incentive gain time should not be considered in determining whether Phillips was in lawful custody at the time commitment proceedings were initiated. The .State contends that if only basic gain time had been awarded, then Phillips would have been in lawful custody when commitment proceedings were commenced. However, the State has pointed to no authority to support its contention that basic and incentive gain time should be treated differently-
Under section 944.275(4)(b), Florida Statutes (1989),6 incentive gain time “shall be credited and applied monthly.” In September 2005, when the post-conviction court ordered that Phillips receive credit against the sentence imposed *956upon revocation of probation for the time previously served in prison, he had already been awarded incentive gain time. Both basic and incentive gain time become vested rights once awarded, subject to all other applicable statutory conditions. Waldrup v. Dugger, 562 So.2d 687, 694 (Fla. 1990); Davis v. Singletary, 659 So.2d 1126, 1127 n. 3 (Fla. 2d DCA 1995). Thus, the incentive gain time already earned and calculated is properly included in determining whether Phillips was lawfully in custody at the time of the commencement of commitment proceedings.
We appreciate the dissent’s ac-knowledgement of our attempt “to remain obedient to the supreme court’s precedent in Larimore and Atkinson.” However, we do not share the dissent’s view that the facts of this case may be distinguished from that supreme court precedent. First, there is no evidence in our record that Phillips intentionally delayed action in order to deprive the Department of Children and Family Services of jurisdiction. In fact, as the dissent recognizes, Phillips appropriately filed a motion to correct his sentence months before his legal sentence expired, but the postconviction court did not resolve the motion for nearly six months. Second, we are unable to agree •with the dissent’s position that Larimore and Atkinson should not apply because the circuit judge, Phillips’ attorney, and the prosecutor were not conversant with the applicable sentencing law. Any such misunderstanding or confusion does not turn an illegal sentence into a legal sentence. Finally, the dissent suggests that defense counsel “is well advised to assure there is an unpreserved error in jail or prison credit” so that the defendant can delay correction of the error until it is too late to initiate commitment proceedings. The documents before us do not suggest this occurred in the present case. Moreover, while defense attorneys must zealously represent their clients, they must also fulfill their duty of candor towards the courts and must avoid conduct that undermines the integrity of the process. See R. Regulating Fla. Bar 4-3.3 cmt. Ultimately, though, it is the responsibility of judges and prosecutors to ensure that legal sentences are imposed and that errors are timely corrected.
Based on the gain time awarded and the application of prior prison credit in this case, Phillips’ custodial sentence legally expired on August 31, 2005, well before the State initiated commitment proceedings in December 2005. Because Phillips was not in lawful custody at the time that proceedings under the Act were commenced, the circuit court does not have jurisdiction to adjudicate the commitment petition filed against Phillips under the Act. We therefore grant Phillips’s petition for writ of prohibition and dismiss the State’s commitment petition with prejudice. Phillips shall be immediately released from any custody or detention that has been imposed as a result of the commitment proceedings.
Because our ruling may preclude the civil commitment of persons who otherwise qualify as sexually violent predators, we certify the following question to the supreme court as one of great public importance:
DOES THE STATE HAVE JURISDICTION TO INITIATE CIVIL COMMITMENT PROCEEDINGS UNDER THE INVOLUNTARY CIVIL COMMITMENT OF SEXUALLY VIOLENT PREDATORS ACT AGAINST AN INMATE WHO IS ENTITLED TO IMMEDIATE RELEASE BASED ON A CORRECTED AWARD OF GAIN TIME?
Petition granted.*957SILBERMAN and CRENSHAW, JJ., Concur. ALTENBERND, Judge, Concurs in part and dissents in part with opinion.
. The Involuntary Civil Commitment of Sexually Violent Predators Act, section 394.910-931, Florida Statutes (2005), is also known as the Jimmy Ryce Act.
. A petition for writ of prohibition is a proper vehicle to challenge the court’s lack of subject matter jurisdiction. See Citizens Prop. Ins. Corp. v. Garfinkel, 25 So.3d 62, 63 (Fla. 5th DCA 2009); Lee v. Campion, 823 So.2d 159, 159 (Fla. 4th DCA 2002); see also Larimore v. State, 2 So.3d 101, 117 (Fla.2008) (quashing decision denying petition for writ of prohibition sought to request dismissal of civil commitment petition based on lack of jurisdiction).
. Section 394.9135(1), Florida Statutes (2005), provides as follows:
If the anticipated release from total confinement of a person who has been convicted of a sexually violent offense becomes immediate for any reason, the agency with jurisdiction shall upon immediate release from total confinement transfer that person to the custody of the Department of Children and Family Services to be held in an appropriate secure facility.
. Section 394.9135(2) requires the multidisciplinary team to determine whether the person qualifies as a sexually violent predator within seventy-two hours. If the multidisciplinary team determines that the person qualifies as a sexually violent predator, it must provide the state attorney with a written assessment and recommendation within the seventy-two-hour time period or within the next working day if the seventy-two-hour time period ends on a weekend or holiday.
.For purposes of the motion to dismiss, the parties stipulated to the accuracy of this affidavit.
. A prisoner's ability to earn gain time is based on the statutes in effect at the time of the offense. See Weaver v. Graham, 450 U.S. 24, 33, 101 S.Ct. 960, 67 L.Ed.2d 17 (1981) (holding that the ex post facto clause applied to changes in gain time statutes). Phillips committed the underlying offenses in December 1989.