The Pennsylvania prison system will stop putting inmates with serious mental illnesses in solitary confinement, instead moving them to special treatment units that allow them more time outside their cells. This shift could impact thousands of inmates in one of the country’s largest prison populations, moving away from practices that the Justice Department described last year as “unjustifiably harsh” for many prisoners.

The change was announced Tuesday as part of a settlement between the Pennsylvania Department of Corrections and the Disability Rights Network of Pennsylvania, nearly two years after the rights network filed a lawsuit against the corrections department. This suit, filed in the U.S. District Court for the Middle District of Pennsylvania, argued that the Department of Corrections had violated the constitutional rights of inmates with serious mental illnesses by moving them to isolated cells.

Inmates placed in isolated cells, known within the Pennsylvania system as “restricted housing units,” are confined there for at least 23 hours a day. Many inmates were placed in these cells for actions that were attributable to their serious mental illness, and this isolation would only exacerbate their symptoms, the Disability Rights Network’s lawsuit.

In the future, inmates who are judged to be a danger to the prison staff and other inmates will be taken to different units, and they will be given at least 20 hours out of their cells per week with the possibility of additional time, the settlement says. The Department of Corrections also said it is developing better ways to identify and treat inmates with severe mental illnesses, a process that will involve improved crisis and mental-health training for prison staff members.

The Department of Corrections and Disability Rights Network praised their agreement Tuesday as being a way to properly treat prisoners. Inmates will now “be able to maintain their mental stability, take advantage of parole-eligibility programming, and serve their sentences in a way that does not punish them merely for having a serious mental illness,” Peri Jude Radecic, the group’s chief executive in Pennsylvania, said in a statement. “This settlement has teeth.”

A civil rights investigation the Justice Department looking into how the state’s prisons handled these inmates and solitary confinement determined last year that the system acted “in ways that violate the rights of prisoners” with serious mental health issues. Investigators found that hundreds of these prisoners were “in solitary confinement for months and sometimes years, with devastating consequences to their mental health.”

This investigation found that between May 2012 and May 2013, more than 1,000 inmates on a mental health roster spent at least three months in solitary confinement. Almost 250 of them were isolated for more than a year. This is how the Justice Department’s report summarized the conditions faced by these prisoners:

They are routinely confined to their cells for 23 hours a day; denied adequate mental health care; and subjected to punitive behavior modification plans, forced idleness and loneliness, unsettling noise and stench, harassment by correctional officers, and the excessive use of full-body restraints.

John Wetzel, secretary of the Pennsylvania Department of Corrections, said last year in response that the investigation focused on information from between one and two years earlier, so it did “not reflect the reality” of how the prison system was being operated by the time the investigation’s findings were released in February 2014. The investigation noted last year that the state was placing fewer of these prisoners in isolation, something the Department of Corrections also said this week.

Solitary confinement is a controversial tactic, one that has been criticized by a host of groups over the years. Amnesty International pointed to studies finding that lengthy isolation can cause depression, anxiety, memory problems and other issues. The Commission on Safety and Abuse in America’s Prisons called for limits on how solitary is used in the country, while the U.S. Government Accountability Office said that the the federal Bureau of Prisons should study the impact of long-term isolation.

It is not known precisely how many inmates are in solitary at any given moment. Solitary Watch, a media and advocacy project, pointed to a 2005 study finding 25,000 prisoners in solitary at supermax prisons and another survey finding that about 81,000 inmates were in some form of “restricted” housing; it estimated this week that there are more than 80,000 prisoners isolated on any given day. We do not know the precise number because of gaps involved in how the data is collected, differences from state to state and uncertainty regarding how solitary is defined, according to Solitary Watch.

Not everyone has a problem finding a definition of solitary. In a 2009 article for the New Yorker, Atul Gawande, a surgeon and public-health writer, came to this conclusion about isolation in prisons:

The simple truth is that public sentiment in America is the reason that solitary confinement has exploded in this country, even as other Western nations have taken steps to reduce it. … In much the same way that a previous generation of Americans countenanced legalized segregation, ours has countenanced legalized torture. And there is no clearer manifestation of this than our routine use of solitary confinement — on our own people, in our own communities, in a supermax prison, for example, that is a thirty-minute drive from my door.

There was renewed movement against the practice last year. In 2014, 10 states adopted more than a dozen measures meant to limit the use of solitary, stop using it for younger inmates or improve conditions, the Marshall Project reported. New York ended the practice for juvenile inmates, while states such as Indiana and Ohio limited the amount of time juveniles can be placed in solitary. As a result of a settlement reached between Arizona and the American Civil Liberties Union, inmates with serious mental health issues in that state will be able to spend more time outside their cells.

Shifts like those in Pennsylvania and other states do not touch on all of the issues facing our country’s prison system. There were more than 50,000 inmates in the Pennsylvania prison system as of November 2014, which exceeded its intended capacity by about 3,800 inmates, according to the Department of Corrections. This is a problem nationwide, as states across the country have far more inmates than their prisons were designed to hold. Meanwhile, more than 1.5 million people were in state and federal prisons at the end of 2013, a slight increase from a year earlier, the Bureau of Justice Statistics reported.

The Justice Department said last fall that the federal prison population had declined in 2014, its first drop in more than three decades. But this wasn’t expected to result in any prison closures, since the prison system still had about 30 percent more inmates than its capacity.