California has agreed to end its controversial practice of indefinite solitary confinement of former gang leaders.

After a settlement was reached Tuesday, the California Department of Corrections and Rehabilitation agreed to only isolate inmates who commit crimes behind bars, not for what they have done outside of prison. This settlement was in response to a class-action federal lawsuit filed on behalf of nearly 3,000 California inmates held in solitary confinement.

California has long used the practice of solitary confinement in response to problem inmates. For gang leaders, the advantage was clear: remove the inmate from the rest of the population to avoid orders being given. However, the practice snowballed in size and length.

Solitary confinement began in the 1800s and was not originally designed as a punishment. It was an opportunity for biblical self-reflection. The practice shifted to a go-to punishment after 1983 when two prison guards were murdered in Marion, Ill. Estimates put anywhere from 25,000 to 80,000 US inmates in solitary confinement at any given time.

Two killers serving time in Pelican Bay initially filed the 2009 class-action lawsuit that brought about the settlement. By 2012, the inmates were two of 78 prisoners confined in solitary for more than 20 years in Pelican Bay. More than 500 inmates had been confined to solitary for more than 10 years.

The inmates spent time confined alone in a cell for around 23 hours a day.

In recent years, public opinion has been shifting away from the practice with criticism being drawn by President Obama and US Supreme Court Justice Anthony Kennedy. The United Nations also viewed many cases where the practice was used as equitable to torture.

“I think there is a deepening movement away from solitary confinement in the country and I think this settlement will spur that movement,” Jules Lobel, the lead attorney for the class-action lawsuit and president of the Center for Constitutional Rights, told the Associated Press a phone interview.

With the new settlement deal, California will no longer have the right to indefinitely keep gang members in solitary confinement. At most, inmates will only be kept in solitary confinement for up to 5 years, with the potential for time added for gang members.

This report includes material from the Associated Press.