SACRAMENTO, Calif. (AP) — The California Supreme Court on Monday reversed the death penalty for a woman who killed her four young daughters and tried to kill her son by setting their house on fire 23 years ago.

The justices unanimously upheld the first-degree murder, attempted murder and arson convictions of 57-year-old Sandi Dawn Nieves in the deaths of daughters Nikolet Amber Nieves, Rashel Hollie Nieves, Kristl Dawn Folden, and Jaqlene Marie Folden.

READ MORE: State Water Officials Preparing To Make Emergency Cutbacks To Growers And Ranchers

But they overturned her death sentence “due to the trial court’s misconduct.”

Mother Sandi Nieves in a family photo with her son and four daughters. She took the witness stand in San Fernando court on Monday and denied that she killed her four daughters in their Saugus home last year. They are pictured here in this family photo, along with her. The son, survived. (Photo by David Bohrer/Los Angeles Times via Getty Images)

The judge was frustrated that the defense lawyer kept violating court procedures despite repeated warnings and sanctions, and also openly doubted the credibility of defense witnesses, the justices found.

“Ultimately, the trial judge’s conspicuous disdain for defense counsel and witnesses, and his repeated references to their improper or untrustworthy conduct, lent credence to the prosecution’s argument that defendant was manipulative and deceitful,” Chief Justice Tani Cantil-Sakauye wrote.

“These were the very characteristics the prosecution highlighted to justify the death penalty.”

Los Angeles Superior Court Judge L. Jeffrey Wiatt killed himself in 2005 after he was questioned by detectives on an unrelated matter.

Nieves was one of 23 women on California’s death row, and is housed at the Central California Women’s Facility in Chowchilla. There are 682 men on the nation’s largest death row, though California has not executed anyone since 2006 and Gov. Gavin Newsom has imposed a moratorium.

Nieves called firefighters July 1, 1998, to report her house was on fire. The blaze was out by the time they arrived and they found her sitting in the living room with her 14-year-old son, covered in soot.

Her daughters, ages 12, 11, 7, and 5 were lying on sleeping bags in the kitchen, all dead of smoke inhalation. Gasoline had been poured and ignited in the hallway and bedrooms, and the oven was open with burned items inside.

READ MORE: Woman Drowns At Shrinking Folsom Lake, Leaving Young Nephew Alone on Shore

Nieves was upset over the end of a relationship and had a stormy past with the fathers of her children, according to the court.

Her son and two oldest daughters were from her first marriage, the two younger girls from her second, and a third man had just broken up with her for the second time after learning she was pregnant. She had threatened suicide and had an abortion a week before the fire.

In a note to her second husband postmarked the day of the fire, she wrote “Now you don’t have to support any of us!” She sent a letter to the third man saying that “I can’t live without you in my life.”

Nieves testified that she didn’t remember sending the letters and “thought she dreamed about holding a lighter and seeing flames” until she realized she had scorched hair on the back of her hand.

Defense experts testified that she had taken a combination of drugs that could cause her to act while she was “basically unconscious,” said one, or in delirium, said another. Prosecution witnesses disputed those conclusions.

“Absent the trial judge’s persistent, disparaging remarks, a juror might have viewed these circumstances with greater sympathy and concluded the crime was a tragedy lacking the moral culpability to warrant death,” Cantil-Sakauye wrote.

“A juror might also have given greater weight to defendant’s remorse and evidence she had been a loving mother to conclude that life in prison, confronted each day with what she had done to her children, was a fitting punishment.”

The justices rejected multiple other defense claims of trial error, including that the jury was not properly selected or screened to consider a death penalty case involving the four young children.

MORE NEWS: Illegal Dumping Laws Not Being Enforced Along Tuolumne River As Trash Piles Up

The Los Angeles County District Attorney’s Office did not respond to a request for comment.