
157 Ill. App.3d 377 (1987)
510 N.E.2d 555
In re CUSTODY OF NICOLE McCARTHY et al. (Raymond C. Wenk et al., Petitioners-Appellants
v.
Clayton J. McCarthy, Respondent-Appellee).
No. 2-86-0803.
Illinois Appellate Court  Second District.
Opinion filed June 30, 1987.
*378 James A. Campion, of Holstrom & Green, P.C., of Woodstock, for appellants.
Paul W. Barbahen, of O'Brien & Barbahen, of Chicago, for appellee.
Reversed and remanded.
JUSTICE WOODWARD delivered the opinion of the court:
Petitioners Raymond C. Wenk, Patricia Wenk, Dianna Miller, and Ronald Miller appeal from a decision by the trial court: (1) granting respondent's motion to dismiss their motion for temporary permanent custody of minors, Nicole and Clayton McCarthy, Jr., and (2) denying petitioners leave to intervene under section 601(c) of the Illinois Marriage and Dissolution of Marriage Act (Act) (Ill. Rev. Stat. 1985, ch. 40, par. 601(c)). Petitioners Raymond Wenk and Patricia Wenk are the maternal grandparents of the minor children. Petitioner Dianna Miller *379 is the children's maternal aunt and Ronald Miller is her husband. Respondent Clayton McCarthy is the natural father of the minor children.
On May 24, 1984, the children's mother, Yvonne M. McCarthy, filed a petition for marital relief, seeking legal separation or dissolution of marriage against Clayton J. McCarthy. A judgment for dissolution of the marriage was entered on February 13, 1985. The settlement agreement incorporated in the judgment provided for Yvonne to have custody of the minor children and gave respondent visitation rights of one day per week. Respondent was ordered to pay $85 per week in child support.
On July 12, 1985, Yvonne McCarthy was killed in an automobile accident. On July 15, 1985, respondent filed an emergency affidavit and petition seeking temporary and permanent custody of the minor children and permission to remove the children to the State of Wisconsin. On this same date, the court entered an order granting custody of the minor children to the petitioner Dianna Miller until July 24, 1985.
On July 22, 1985, petitioners Dianna L. Miller and Ronald N. Miller and/or in the alternative Raymond Wenk and Patricia Wenk filed their petition for custody of the minor children pursuant to section 601(b)(2) of the Act (Ill. Rev. Stat. 1985, ch. 40, par. 601(b)(2)). On July 24, 1985, respondent filed his answer to the petitioners' petition for custody and therein moved to strike on the grounds that section 601(b)(2) did not provide for alternative pleadings, but he did not raise the question of petitioner's standing under section 601(b)(2). The court denied the respondent's motion to strike the alternative relief sought in the petition of the petitioners for custody. Then, on July 29, 1985, respondent filed a motion for temporary custody pending temporary hearing. The court entered an order on August 2, 1985, which denied respondent's motion for temporary custody pending the hearing and provided that the minor children should remain in the temporary custody of Dianna Miller. The children remained in her custody throughout the permanent custody hearings. The respondent married Candy Kamen on July 31, 1985.
From and including July 15, 1985, through June 11, 1986, the court conducted a continuing hearing regarding the permanent custody of the minor children. The court heard the testimony of over 30 witnesses. Approximately 3,000 pages of transcript were taken. Petitioners put on 26 witnesses, and respondent put on 10 witnesses.
The petitioners ended their case in chief on October 29, 1985. Respondent moved for a finding in his favor. The court denied this motion *380 on November 12, 1985. Respondent proceeded with his case in chief, which he closed on May 23, 1986. At that time, both petitioners and respondent moved for findings in their favor. The court denied these motions, and petitioners put on several rebuttal witnesses. On May 1, 1986, respondent filed a motion to dismiss, alleging for the first time that the petitioners had no standing to bring a child custody action pursuant to section 601(b)(2) of the Act (Ill. Rev. Stat. 1985, ch. 40, par. 601(b)(2)). On August 29, 1986, the court entered an order which granted the respondent's motion to dismiss and ordered the minor children transferred to him on September 1, 1986. The court retained jurisdiction of the cause, permitting the respondent to temporarily remove the minor children to Wisconsin for purposes of residence and enrollment in school. This appeal followed. It should be noted that on July 15, 1985, the trial court appointed a guardian ad litem to represent the children in the custody proceeding. The guardian ad litem has chosen not to take part in the appeal. This court draws no inferences or assumptions from the guardian's lack of participation.
On appeal, the petitioners raise three issues: (1) petitioners have standing under section 601(b)(2) of the Act (Ill. Rev. Stat. 1985, ch. 40, par. 601(b)(2)) to initiate an action for child custody; (2) respondent waived his right to object to petitioners' standing by failing to make a timely motion to dismiss; and (3) the trial court abused its discretion by failing to allow petitioners to intervene, pursuant to section 601(c), in the custody proceeding properly commenced and before the court.
 1, 2 We first address the issue of whether or not respondent waived his right to object to petitioners' standing by failing to make a timely motion to dismiss. Lack of standing has been deemed an affirmative defense and, therefore, is subject to section 2-619(a)(9) of the Civil Code of Procedure (Ill. Rev. Stat. 1985, ch. 110, par. 2-619(a)(9)). (Hermes v. Wm. F. Meyer Co. (1978), 65 Ill. App.3d 745.) Section 2-619(a) provides that a motion to dismiss must be brought "within the time for pleading." (Ill. Rev. Stat. 1985, ch. 110, par. 2-619(a).) In the present case, respondent clearly did not file the motion to dismiss within the time for pleading. The motion was filed nine months after evidentiary hearings began. At that time, the court had heard testimony on 16 different days. Nevertheless, the trial court has the discretion to allow the withdrawal of an answer and the subsequent filing of a tardy motion to dismiss based on a defense not raised in the answer. (Midwest Bank & Trust Co. v. Village of Lakewood (1983), 113 Ill. App.3d 962.) Unless it can be demonstrated that the opposing party was prejudiced by the late filing of the motion to *381 dismiss, the trial court does not abuse its discretion by allowing tardy pleadings. Illinois Housing Development Authority v. Sjostrom & Sons, Inc. (1982), 105 Ill. App.3d 247, 253.
 3 Generally, we note the purpose of affirmative defenses, such as lack of standing, is to afford the defendants the means of obtaining at the outset of litigation summary disposition of issues of law or easily proved issues of fact. (Stanley v. Chastek (1962), 34 Ill. App.2d 220.) In other words, these defenses can obviate the need for parties and courts to become mired in causes that could be quickly dispatched. With that purpose in mind, we look at the relevant facts of the instant case to determine if petitioners were prejudiced by the trial court's allowance of respondent's tardy motion to dismiss.
Within days after Yvonne McCarthy's death on July 12, 1985, petitioners and respondent sought legal custody of Nicole and Clayton McCarthy, Jr. Petitioners filed their petition for permanent custody on July 22, 1985, and respondent filed his answer on July 25, 1985. As noted above, the respondent's answer did not object to the petitioners' standing under section 601(b)(2). The trial court began hearings in regard to the petition for permanent custody over a period from July 24, 1985, through June 11, 1986. Both petitioners and respondent moved for findings in their favor, and the court denied these motions. The motion to dismiss on the basis of petitioners' lack of standing was filed on May 1, 1986, and decided on August 29, 1986, at which time the petitioners were ordered to turn over Nicole and Clayton, Jr., to their father.
The court order was evidently based on by In re Custody of Peterson (1986), 112 Ill.2d 48, which was decided on April 6, 1986. In Peterson, maternal grandparents petitioned for modification of custody to obtain custody of their granddaughter after her mother died in May 1984. The child's natural father filed a petition for modification of the divorce decree in order to obtain custody of his child. He then filed a motion to dismiss the grandparents' petition alleging lack of standing. On July 2, 1984, the trial court dismissed the grandparents' petition for custody for lack of standing and ordered that custody be turned over to the father.
Respondent contends that Peterson is controlling on the issue of petitioners' standing. But, in fact, this case differs appreciably from Peterson, in which the natural father made a timely motion to dismiss for lack of standing. The principal issue in Peterson was whether or not the maternal grandparents had standing. The principal issue in the instant case is whether the petitioners were prejudiced by granting respondent's tardy motion to dismiss.
*382  4 Contrary to the instant case, Peterson exemplifies the value of affirmative defenses that are timely put forward. In Peterson, the motion to dismiss for lack of standing obviated the need to put the litigants and the court through a time-consuming and difficult custody hearing. Here, petitioners had to endure a prolonged and difficult custody hearing which was spread out over almost 11 months. They, undoubtedly, incurred large legal fees. The emotional toll of the proceeding must have been significant. Also, petitioners and the minor children were doubtless growing accustomed to living with the petitioners. Petitioners were severely prejudiced when the trial court granted the late motion to dismiss. We find that petitioners have shown that they were prejudiced by the granting of the tardy motion to dismiss, and, therefore, the trial court abused its discretion by dismissing petitioners for lack of standing.
In support of our position, we cite Midwest Bank & Trust Co. v. Village of Lakewood (1983), 113 Ill. App.3d 962. In Midwest Bank the defendant's answer was on file, and the trial of the cause was beginning when defendant's oral motion to dismiss was made. The reviewing court concluded that this motion to dismiss was clearly not within the time for pleading. It noted that the trial court did have the discretion to allow a defendant to withdraw an answer and then file a motion to dismiss based upon a defense not raised in the withdrawn answer. But the Midwest Bank trial court had granted the motion after defendant's answer was filed and the trial had begun. The reviewing court concluded that this constituted an abuse of discretion. In the instant case, the hearing for permanent custody had almost concluded when the motion to dismiss was granted.
We therefore find that respondent had waived all objections to petitioners' standing by his failure to make a more timely motion to dismiss on the basis of petitioners' lack of standing. To hold otherwise would be to allow a gross injustice to the petitioners.
Though it is not necessary for the disposition of this cause, we address the issue of petitioners' standing under section 601(b)(2) of the Act. Petitioners claim they have standing to bring the instant custody action pursuant to section 601(b)(2) of the Act, which reads as follows:
"A child custody proceeding is commenced in court:
* * *
(2) by a person other than a parent, by filing a petition for custody of the child in the county in which he is permanently resident or found, but only if he is not in physical custody of one of his parents." (Emphasis added.) Ill. Rev. Stat. 1985, ch. 40, par. 601(b)(2).
*383 Under the Act (Ill. Rev. Stat. 1985, ch. 40, par. 101 et seq.), non-parents must meet the standing requirement of section 601(b)(2) of the statute before they will be considered as a custodian for a minor child under the Act.
 5, 6 To have standing under section 601(b)(2), petitioners must prove that, upon the death of Yvonne McCarthy on July 12, 1985, Nicole and Clayton, Jr., were not in the physical custody of the respondent. It has long been the law in Illinois that the death of a custodial parent after a final divorce judgment has been entered does not automatically revert custody to the surviving parent. (Milenkovic v. Milenkovic (1981), 93 Ill. App.3d 204, 212.) When a divorced custodial parent dies, the court has the power to determine who should have custody of a child even though the legal custody of the child is not in anyone immediately following the death of the legal custodian. (93 Ill. App.3d 204, 212.) This reasoning arises from the well-established concept that the best interests of the children are the foremost considerations in the custody determinations. Ill. Rev. Stat. 1985, ch. 40, par. 602; In re Wheat (1979), 68 Ill. App.3d 471.
In the instant case, respondent did not have physical custody of the minor children immediately after Yvonne's fatal accident. Respondent sought physical possession by filing a petition for custody on July 15, 1985. On the same day, the trial court denied respondent's motion and granted temporary custody of the children to petitioner Dianna Miller to July 24, 1985. Petitioners filed their motion for temporary and permanent custody of the children on July 22, 1985. Evidence on the petitioner's petition began being heard on July 24. Respondent filed a motion for temporary custody pending the temporary hearing on July 29, 1986. The trial court, on July 30, 1986, found that there had been a prior hearing as to temporary custody and, therefore, denied respondent's motion for physical custody pending a determination of the issue of permanent custody.
Petitioner Dianna Miller retained custody of the children throughout the custody proceeding and until September 1, 1986.
 7 From these facts, it is clear that the trial court had ample opportunity to transfer temporary custody (which obviously includes physical custody) to the respondent. At no time did it exercise that option. Rather, it awarded temporary custody to petitioner Dianna Miller on July 15, 1985, and reaffirmed that order on July 30, 1985. Petitioner's temporary custody of the children lasted until September 1, 1986. For purposes of section 601(b)(2), the respondent never had physical custody of Nicole and Clayton, Jr., in the relevant period following Yvonne's death. The court had vested that physical custody in *384 the petitioner Dianna Miller who asserts that she had standing under section 601(b)(2) because the surviving parent did not have physical custody of the minor children. The petitioners have met the requirement of showing that the children were not in the physical custody of one of the parents, and, accordingly, the trial court erred in holding that the petitioners did not have standing under section 601(b)(2).
There being no question as to the standing of the petitioners in this proceeding, this cause is remanded to the trial court for determination based on the evidence adduced at the prior custody hearings, and any further evidence the parties may desire to adduce, and the trial court is directed to decide the issue of permanent custody of Nicole and Clayton, Jr., pursuant to the "best interest of the child" standard. In re Custody of Townsend (1981), 86 Ill.2d 502, 508.
For the reasons stated above, we reverse the trial court's decision and remand the cause for further proceedings consistent with this opinion.
Reversed and remanded.
NASH and HOPF, JJ., concur.
