General Laws c. 123, § 17 (b), provides that an incompetent defendant may “request an opportunity to offer a defense” to charges pending against him and states that “[i]f after hearing [the defendant’s] petition the court finds a lack of substantial evidence to support a conviction it shall dismiss the indictment or other charges.” In the present case, we clarify the scope of a hearing held pursuant to this statutory provision.
1. Factual and procedural background. On an unknown date between June 29, 1997, and July 5, 1997, the defendant, then sixteen years old, allegedly raped and committed other acts of *619sexual abuse against a ten year old girl. In October, 1997, the defendant was indicted as a youthful offender for rape of a child, in violation of G. L. c. 265, § 23; indecent assault and battery on a child under fourteen years of age, in violation of G. L. c. 265, § 13B; and unnatural and lascivious acts on a child under sixteen years of age, in violation of G. L. c. 272, § 35A. Following an evidentiary hearing, a District Court judge found that the defendant was incompetent to stand trial.
The defendant filed a motion pursuant to G. L. c. 123, § 17 (b), for leave to offer a defense on the merits to the charges against him. In support of such motion, defense counsel stated that he had conducted an investigation into the Commonwealth’s allegations. He would show that there was a lack of substantial evidence to support the complainant’s testimony and that, depending on the exact dates of the alleged offenses, the defendant would present evidence of an alibi. The judge, in his discretion, granted the defendant’s motion. A hearing was then held to determine the appropriate procedure for a § 17 (b) proceeding. In his memorandum of decision, the judge stated that he would apply a “required finding of not guilty” standard to determine whether there was a “lack of substantial evidence to support a conviction.” The judge further stated that he would allow the defendant to present testimony from the complaining witness at the hearing. The Commonwealth filed a petition pursuant to G. L. c. 211, § 3, challenging the decision of the District Court judge. A single justice of this court reserved and reported the case, without decision, to the full court.
2. Statutory background. General Laws c. 123, § 17 (b), is a component of mental health legislation that was enacted, in part, to address the issue of pretrial commitment of incompetent criminal defendants. See St. 1970, c. 888, § 4; Foss v. Commonwealth, 437 Mass. 584, 587-589 (2002). A person charged with a criminal offense who is found to be legally incompetent will not be required to stand trial, because to do so would violate his constitutional rights of due process. See Commonwealth v. Vailes, 360 Mass. 522, 524 (1971). However, such a defendant still faces the possibility of eventual criminal prosecution because the “trial of the case shall be stayed until such time as the defendant becomes competent to stand trial, unless the case *620is dismissed.” G. L. c. 123, § 15 (d). Dismissal is the ultimate relief from indefinite pretrial commitment.
There are two avenues by which the charges against an incompetent defendant may be dismissed. First, such charges will be dismissed on “the date of the expiration of the period of time equal to the time of imprisonment which the person would have had to serve prior to becoming eligible for parole if he had been convicted of the most serious crime with which he was charged in court and sentenced to the maximum sentence he could have received, if so convicted.” G. L. c. 123, § 16 (f). This statutory provision “balances the interests of an incompetent defendant in dismissal of pending charges with the interests of the Commonwealth in protecting the public and enforcing the law by providing that the charges may remain pending for a period determined on the basis of the single most serious crime charged and the maximum sentence possible therefor.” Foss v. Commonwealth, supra at 591. In the alternative, G. L. c. 123, § 17 (b), gives an incompetent defendant the opportunity to have the criminal charges against him dismissed before the date when he would have been eligible for parole if certain conditions are satisfied. It provides as follows:
“If either a person or counsel of a person who has been found to be incompetent to stand trial believes that he can establish a defense of not guilty to the charges pending against the person other than the defense of not guilty by reason of mental illness or mental defect, he may request an opportunity to offer a defense thereto on the merits before the court which has criminal jurisdiction. The court may require counsel for the defendant to support the request by affidavit or other evidence. If the court in its discretion grants such a request, the evidence of the defendant and of the commonwealth shall be heard by the court sitting without a jury. If after hearing such petition the court finds a lack of substantial evidence to support a conviction it shall dismiss the indictment or other charges or find them defective or insufficient and order the release of the defendant from criminal custody.”
G. L. c. 123, § 17 (b). We now consider the purpose and meaning of this statutory provision.
*6213. Standard of proof The Commonwealth contends that the District Court judge committed reversible error by setting forth the wrong standard of proof that would be applicable to the defendant’s § 17 (b) hearing. The Commonwealth asserts that the judge ignored the statutorily mandated “substantial evidence” standard in favor of the “required finding of not guilty” standard set forth in Myers v. Commonwealth, 363 Mass. 843 (1973).
We initially note that when an incompetent defendant requests an opportunity to offer a defense to the charges pending against him, other than a defense of not guilty by reason of mental illness or mental defect, he must make a preliminary showing that his request should be allowed. The language of G. L. c. 123, § 17 (b), that “[t]he court may require counsel for the defendant to support the request by affidavit or other evidence” suggests that the mere assertion by the defendant that he wants to present a defense will be insufficient to warrant a hearing, particularly where the statute vests the court with discretion to grant or deny the defendant’s request. Cf. Fauci v. Mulready, 337 Mass. 532, 540 (1958) (province of judge to decide any preliminary questions of fact). The presentation of an “affidavit” or “other evidence” will bolster the defendant’s claim that he does, in fact, have a specific and arguably meritorious defense to the pending charges.
Once a judge grants a defendant’s request for an opportunity to present a defense “on the merits,” the standard by which the judge must decide whether the indictment or other charges should be dismissed is whether there is “a lack of substantial evidence to support a conviction.” G. L. c. 123, § 17 (b). See Spero v. Commonwealth, 424 Mass. 1017, 1018 (1997). General Laws c. 123, § 17 (b), offers an incompetent defendant relief from the indefinite pendency of criminal charges where conviction is not likely. See Jackson v. Indiana, 406 U.S. 715, 740-741 (1972). In essence, it requires the judge to determine whether there is sufficient evidence to continue holding the defendant for trial in the event that, at some time in the future, he becomes competent to stand trial. In accomplishing such task, a judge’s role has been defined by the Legislature in § 17 (b).
*622“[T]he primary source of insight into the intent of the Legislature is the language of the statute.” International Fid. Ins. Co. v. Wilson, 387 Mass. 841, 853 (1983). It is a fundamental principle of statutory construction that “statutory language should be given effect consistent with its plain meaning and in light of the aim of the Legislature unless to do so would achieve an illogical result.” Sullivan v. Brookline, 435 Mass. 353, 360 (2001). See Boston Water & Sewer Comm’n v. Metropolitan Dist. Comm’n, 408 Mass. 572, 578 (1990) (Legislature presumed to understand and intend all consequences of its acts). As such, a judge must give full effect to the Legislature’s use of the words “lack of substantial evidence to support a conviction” in evaluating whether to dismiss the indictment or other charges against the defendant. “Substantial evidence” means “such evidence as a reasonable mind might accept as adequate to support a conclusion.” G. L. c. 30A, § 1 (6). See New Boston Garden Corp. v. Assessors of Boston, 383 Mass. 456, 466 (1981). The “substantial evidence” standard is neither novel, nor one with which the Legislature is unfamiliar. Where, as here, the language of a statute is clear and unambiguous, it is conclusive as to legislative intent. See Pyle v. School Comm. of S. Hadley, 423 Mass. 283, 285 (1996). If the Legislature had intended for a different standard to be applied to hearings held pursuant to G. L. c. 123, § 17 (b), such as the familiar Myers standard, supra, it would have said so. See Ciardi v. F. Hoffmann-La Roche, Ltd., 436 Mass. 53, 63 (2002).
The standard of proof under G. L. c. 123, § 17 (d), is not, however, a civil standard, as the Commonwealth urges. The plain meaning of “substantial evidence to support a conviction” requires the Commonwealth to present substantial evidence from which a rational jury could convict the defendant, that is, find him guilty beyond a reasonable doubt. While, in its practical application, the standard may well yield the same result as the standard for deciding a motion for required finding of not guilty under Mass. R. Crim. R 25 (a), (b) (1), 378 Mass. 896 (1979), the role of the judge under § 17 (b) is different from that of the judge under rule 25 (a), (b) (1), and we articulate the standard with reference to the extensive jurisprudence concerning the substantial evidence standard, as that is the test articulated by the Legislature in § 17 (b).
*623The substantial evidence standard under § 17 (b) requires a judge to decide “whether experience permits the reasoning mind to make the finding [of guilt] . . . whether the finding [of guilt] could have been made by reference to the logic of experience.” Boston Edison Co. v. Selectmen of Concord, 355 Mass. 79, 92 (1968), quoting L.L. Jaffe, Judicial Control of Administrative Action 598 (1965). The judge’s determination must be made “upon consideration of the entire record” (emphasis added). Cohen v. Board of Registration in Pharmacy, 350 Mass. 246, 253 (1966), quoting G. L. c. 30A, § 14. “The substantiality of evidence must take into account whatever in the record fairly detracts from its weight.” Cohen v. Board of Registration in Pharmacy, supra, quoting Universal Camera Corp. v. NLRB, 340 U.S. 474, 488 (1951). It thus requires a judge to weigh all the evidence, including evidence adduced by the defendant, and assess the credibility of all witnesses.
Although a judge must weigh all the evidence and assess the credibility of all witnesses at a hearing under § 17 (b), the determination whether there is a lack of substantial evidence to support a conviction must not be based on the judge’s personal view of the evidence, but on whether a rational jury could find the defendant guilty beyond a reasonable doubt. See Labor Relations Comm’n v. University Hosp., Inc., 359 Mass. 516, 521 (1971) (where fact finder made “choice between two fairly conflicting views” supported by substantial evidence, “court may not displace [fact finder’s] choice . . . even though the court would justifiably have made a different choice had the matter been before it de novo”). If the weight of the credible evidence could not lead a rational jury to find the defendant guilty beyond a reasonable doubt, then the defendant is entitled to a dismissal under § 17 (b).1
The “substantial evidence to support a conviction” standard *624is more burdensome to the Commonwealth than the required finding of not guilty standard. The former requires the judge to measure the Commonwealth’s case against the entire record, including the contrary evidence presented by the defendant; the latter only requires the judge to consider “the evidence in its light most favorable to the Commonwealth, notwithstanding the contrary evidence presented by the defendant.” Commonwealth v. Latimore, 378 Mass. 671, 676-677 (1979). The Legislature may well have required this more demanding standard because incompetent defendants may be incarcerated for lengthy periods, even for fife, without a trial. To offset this detriment, the Commonwealth must show more than that it is entitled to have a jury consider its case. Further justification for this approach is that, because jeopardy never attaches, a dismissal under § 17 (b) is not a final determination. The Commonwealth may re-indict if it obtains additional evidence. See Burke v. Commonwealth, 373 Mass. 157, 161-162 (1977).
4. Presentation of witness testimony. The Commonwealth contends that the District Court judge committed reversible error by concluding that the defendant could call the complainant as a witness at his § 17 (b) hearing. The Commonwealth argues that the statute does not provide for the introduction of live testimony, and that the complainant was unlikély to provide any relevant and material evidence that would support the defendant’s proposed alibi defense. We disagree.
The defendant clearly has a right to call witnesses at a § 17 (b) hearing. The statute explicitly provides that the defendant may offer a “defense ... on the merits before the court which has-criminal jurisdiction” and that “the evidence of the defendant and of the commonwealth shall be heard by the court sitting without a jury.” G. L. c. 123, § 17 (b). As we have earlier noted, the words of a statute are the primary source from which we ascertain legislative purpose, and when the text of a statute is clear and unambiguous, we constme the language in accordance with its plain and ordinary meaning. See Commonwealth v. Ray, 435 Mass. 249, 252 (2001), and cases cited. The language of *625G. L. c. 123, § 17 (b), unambiguously allows a judge to “hear” testimonial evidence presented by the defendant and the Commonwealth. Such testimony would be critical to the judge’s determination whether there was “a lack of substantial evidence to support a conviction,” particularly where we have concluded that the judge’s role includes the assessment of witness credibility. In his request for a § 17 (b) hearing, the defendant stated that he would be able to show substantial evidence of an alibi. The testimony of the complainant would be relevant and material as to the dates and times of the alleged sexual assaults by the defendant. Moreover, the complainant’s inability to provide details of such incidents would be an important determinant whether there was “a lack of substantial evidence to support a conviction.”2
The Commonwealth asserts that because of the complainant’s young age, her “limited intellectual development,” and her “history of psychiatric hospitalization,” she should not be compelled to testify at the defendant’s § 17 (b) hearing. We note that there is no evidence in the record on which this case was reserved and reported that the Commonwealth requested any special accommodations for the complainant. “This court is acutely aware of the plight of child sexual assault victims and traditionally has been sensitive toward meeting the needs of these young witnesses.” Commonwealth v. Bergstrom, 402 Mass. 534, 552 (1988). See, e.g., G. L. c. 278, § 16A (permitting judge to exclude public from court room where victim of sexual offense is under eighteen years of age). See also Commonwealth v. Brusgulis, 398 Mass. 325, 332 (1986) (“Judges have considerable latitude in devising procedures and modifying the usual rules of trial to accommodate child and other witnesses with special needs, so long as the defendant’s fair trial rights are not violated”). It is well within the province of the judge to take such measures as he deems appropriate to reduce the adverse impact of the § 17 (b) hearing on the complainant, *626including, for example, creating a less formal environment in which to hear her testimony and making available court-supervised counselling services to the extent necessary. See Commonwealth v. Bergstrom, supra at 553-554.
The Commonwealth’s argument that the defendant should not be allowed to call witnesses because he is incompetent and therefore unable to assist in his own defense evinces a misunderstanding of the function of a § 17 (b) hearing. In the first place, it only pertains to defendants who are incompetent. Second, the hearing primarily serves a screening function; it is not a trial to establish guilt, and it is not going to result in a defendant’s conviction and sentencing. At the conclusion of the hearing, an incompetent defendant will be in no worse position than he was before the hearing and, in fact, he may be in a better position. The judge will either determine that the charges against him should be dismissed, or the judge will maintain the status quo. The fact that a defendant has been deemed incompetent to stand trial has no bearing on his ability, or that of his attorney, to present evidence at a § 17 (b) hearing. The Supreme Court has noted that it is desirable to afford incompetent defendants some opportunity to establish innocence without exposure to being convicted. See Jackson v. Indiana, supra at 740, 741 & n.30, citing G. L. c. 123, § 17. Contrast Commonwealth v. Vailes, 360 Mass. 522, 524 (1971) (“The trial, conviction or sentencing of a person charged with a criminal of-fence while he is legally incompetent violates his constitutional rights of due process”).
This case is remanded to the county court where an order will enter remanding the case to the District Court for further proceedings consistent with this opinion.
So ordered.
Following a hearing pursuant to G. L. c. 123, § 17 (b), if the judge finds that there is “a lack of substantial evidence to support a conviction,” the ultimate result is not the defendant’s acquittal, but rather dismissal of the indictment or other charges and his release from criminal custody. Such result emphasizes a major purpose of G. L. c. 123, namely, “to eliminate the highly questionable practice of committing incompetent criminal defendants indefinitely, while awaiting their unlikely restoration to competency, and also eliminating the indefinite pendency of criminal charges that, most often, *624significantly limited the incompetent criminal defendant’s access to treatment by more effective civil means.” Foss v. Commonwealth, 437 Mass. 584, 589 (2002).
Both G. L. c. 276, § 38, and G. L. c. 123A, § 12 (d), include specific language that a defendant has the right to cross-examine witnesses in support of the prosecution. Although G. L. c. 123, § 17 (b), does not include such language, it does state that a defendant may offer a defense “on the merits,” which we construe to include the right to cross-examine witnesses presented by the Commonwealth.