A judge on Tuesday accepted James Holmes’ plea of not guilty by reason of insanity, setting the stage for a lengthy mental evaluation of the Colorado theater shooting suspect.

The court clerk placed a written advisory of the ground rules of the plea before Holmes so he could examine it as Judge Carlos Samour Jr. read through all 18 points.

When Samour asked if he had any questions, Holmes replied no. Samour then accepted the plea.

“I find Mr. Holmes understands the effects and consequences of the not guilty by reason of insanity plea,” the judge said. “He was looking at the advisement and appeared to be following along.”

Holmes is accused of opening fire in a packed Denver-area movie theater last summer, killing 12 people and injuring 70. He is charged with multiple counts of murder and attempted murder, and prosecutors are seeking the death penalty.

Holmes’ lawyers repeatedly have said he is mentally ill, but they delayed the insanity plea while arguing state laws were unconstitutional. They said the laws could hobble the defense if Holmes’ case should ever reach the phase where the jury decides if he should be executed.

The judge rejected that argument last week.

Hundreds of people were watching a midnight showing of The Dark Knight Rises at the Aurora theater when the shooting occurred July 20.

The dead included a Navy veteran who threw himself in front of his friends to shield them, an aspiring sports journalist who had survived a mall shooting just two months earlier, and a 6-year-old girl.

Prosecutors say Holmes spent months buying weapons, ammunition and materials for explosives and scouted the theater in advance. He donned police-style body armor, tossed a gas canister into the seats and opened fire, they say.

The insanity plea is widely seen as Holmes’ best chance of avoiding execution, and possibly his only chance, given the weight of the evidence against him.

But his lawyers delayed it for weeks, saying Colorado’s laws on the insanity plea and the death penalty could work in combination to violate his constitutional rights.

The laws state that if Holmes does not cooperate with doctors conducting a mandatory mental evaluation, he would lose the right to call expert witnesses to testify about his sanity during the penalty phase of his trial. Defense lawyers argued that is an unconstitutional restriction on his right to build a defense. They also contended the law doesn’t define cooperation.

Samour rejected those arguments last week and said the laws are constitutional.

The next step is an evaluation of Holmes by state doctors to determine whether he was insane at the time of the shootings. That could take months.

Colorado law defines insanity as the inability to distinguish right from wrong caused by a diseased or defective mind.

If jurors find Holmes not guilty by reason of insanity, he would be committed indefinitely to the state mental hospital. He could eventually be released if doctors find his sanity has been restored, but that is considered unlikely.

If jurors convict him, the next step is the penalty phase, during which both sides call witnesses to testify about factors that could affect why Holmes should or shouldn’t be executed.

The jury would then decide whether Holmes should be executed or sentenced to life in prison without possibility of parole.

If jurors impose the death penalty, it would trigger court appeals and open other possibilities that would take years to resolve.

Read more: