SACRAMENTO, Calif. (AP) — Special California prisons intended to protect gang informants, disgraced cops and child molesters have become so violent, gang-riddled and crowded that officials are dismantling what’s become the United States’ largest protective custody program.

The inmates are gradually being integrated into the general prison population, where some advocacy groups fear they will be even worse off.

California created the so-called Sensitive Needs Yards nearly two decades ago.

By 2015, their population ballooned to about a third of the state prison system’s 130,000 inmates, with all the problems of a mainline prison: nearly 100 gangs; smuggling of drugs like the Fentanyl that killed one inmate and sickened 12 this spring; and killings like that of 54-year-old Gregory Miley, who was serving time for assisting in the rape, torture and strangling of teenage boys.

Sex offenders in particular were disproportionately dying in the very units created to protect them. The state corrections department’s inspector general reported 10 of the 11 inmate homicides in the first six months of 2014 were in the protective housing units. The Associated Press found eight of the 11 were sex offenders, and determined in a 2015 analysis that male sex offenders were being killed at a rate double their percentage in the prison population.

The special prisons “became as dangerous if not more dangerous than the general population yards,” said Don Specter, director of the nonprofit Prison Law Office, which advocates for inmates and supports the recent changes.

Conditions were so bad by 2015 that the department’s inspector general called for a complete overhaul.

Now, the department is integrating lower-security protective custody inmates into units that promise expanded privileges and rehabilitation programs, hoping an easier time in prison and the possibility of earlier parole will encourage good behavior.

“The department needs to continue moving in this direction if we’re ever going to have a system that is changing from the punitive, ‘Lock ’em up and keep ’em inside the wire until their incarceration’s done’ to a time when an inmate can avail themselves to the programs that we have and become rehabilitated and change,” Corrections Secretary Scott Kernan said.

The prison system’s main hospital and its mental health units also now are integrated, and the department plans to include protective custody inmates on firefighting teams and at minimum-security facilities that provide custodial and other services to more secure prisons.

Some higher-security prisons that house sick or mentally ill protective custody inmates will eventually be integrated. But it is unlikely prison officials will be able to do away with Sensitive Needs Yards entirely, Kernan said.

The prototype for integration is a living unit at a San Diego County prison where infamous brothers Lyle and Eric Menendez were reunited in April, nearly three decades after they were convicted of killing their parents. Gang members, sex offenders, transgender inmates and prisoners of all races are expected to get along while taking classes and participating in unorthodox activities like art and playwriting classes, musical bands, yoga and training dogs to aid autistic children and wounded veterans.

The transition hasn’t been smooth everywhere.

Officials transferred part of a Northern Hispanic prison gang after members attacked a former protective custody inmate who was moved into San Quentin State Prison, which offers numerous rehabilitation programs. It has made similar mass transfers at several other prisons since then, Kernan said. He said most attacks have been beatings instead of attempted murders.

“The department created this monster, the SNY yard,” said Laura Magnani, an inmate advocate with the American Friends Service Committee, a Quaker organization. “Then overnight they decide, ‘Oh, we don’t need that. We’re not going to provide that anymore.’ All of a sudden the gates open and they’re told, ‘Oh, we need you to show us you can get along.'”

The Sensitive Needs Yards were created in 2002. Criteria was “liberally applied,” according to a 2016 department report, and soon every inmate with a drug or gambling debt, a gang issue or a beef with another inmate was signing up, Kernan said.

Protective custody inmates quickly became the fastest-growing segment of California’s inmate population, rising from 24,000 inmates in 2008 to 41,000 inmates in 2016 even as the overall prison population dropped dramatically.

Legal Services for Prisoners with Children attorney Carol Strickman blames the growth in part on the prison system’s former policy of sending gang members to segregation units where some were isolated for decades. The only way to get out was to denounce the gang, which meant the inmates were then targeted for retaliation as gang turncoats.

Lisa Ells, a lawyer working on a major lawsuit seeking protections for mentally ill prisoners, said encouraging inmates to rehabilitate is laudable.

“The question is, will it work and more importantly can they do it safely and will they do it the right way?” Ells said. “And that’s a very open question.”