U.S. District Judge Lawrence K. Karlton could only stomach six of the 17 videos attorneys wanted to show him before declaring California's treatment of its mentally ill inmates “horrific” and unconstitutional Thursday.

He singled out the excessive use of pepper spray and solitary confinement as examples of cruel and unusual punishment—they are quite usual in California prisons—and gave corrections officials a number of directives in his 74-page order on how to better handle the inmates. He stopped short of banning the practices and gave the state 60 days to change its policies in coordination with the court-appointed special master.

Karlton also gave them 30 days to figure out a way to dramatically reduce or stop the isolation of prisoners when their offense was directly related to their mental illness.

More than a quarter of California's 120,000 prison inmates are mentally ill and have been the subject of an ongoing lawsuit for 24 years. The lawsuit has already resulted in a number of changes, but Karlton said it wasn't nearly enough. One change already made: guards have to wait three minutes between pepper spray dousings.

The judge convened hearings last fall and state officials argued that changes it had already made at his direction had essentially solved the problem. They defended their present policies and argued the force used by guards was not excessive.

Those arguments wilted when the videos, taken by guards (as now required by the corrections department), showed wailing prisoners being drenched with pepper spray before getting whacked with batons and dragged off to solitary confinement. In one video, a pepper-spray canister the size of a fire extinguisher was emptied into a cell. In some cases, the prisoners were being punished because they refused to take their medication.

One video the court did not see was of Joseph Duran, who died September 6, 2013, after being pepper-sprayed for not letting go of his cell's food port. Duran, who was already on suicide watch, breathed with the assistance of a tube in his throat, which he pulled out when sprayed. Guards then refused to remove him despite pleas from medical personnel and he was found dead seven hours later.

Duran's death and the incidents leading up to it were unknown to the court, and Duran's parents, until the Sacramento Bee wrote about it. The parents told the Bee they have filed a wrongful death suit against the state.

Karlton has been sparring with the California Department of Corrections and Rehabilitation (CDCR) since writing the original federal order in 1995 that put the state under federal scrutiny. His latest order recognizes improvements already made by corrections officials and notes that much of what the state has been doing lately is technically legal. But that didn't make it OK.

The judge ordered that mentally ill inmates not be held in solitary confinement for more than 72 hours unless it is part of a specific punishment and said he didn't want medical personnel to be overruled by guards when it came to pepper spraying and isolating prisoners.