The Mississippi Department of Corrections violated the constitutional rights of inmates at a private prison by failing to provide them with "reasonably safe living conditions," a federal judge ruled on Thursday. Conditions at Walnut Grove Correctional Facility are so dire that Judge Carlton Reeves denied the department's request to end a legal agreement forcing the state and its private contractor to reduce violence, fix broken facilities, and improve staff training.

"The evidence before the Court paints a picture of a facility struggling with disorder, periodic mayhem, and staff ineptitude which leads to perpetual danger to the inmates and staff," Reeves wrote in his decision, filed in the U.S. District Court for the Southern District of Mississippi. "The dangers that inmates face are not simply limited to assaults by other inmates but also from the guards."

The agreement to improve conditions in the facility was negotiated between the ACLU and the Mississippi Department of Corrections in 2012. It gave the state five years to get Walnut Grove up to constitutional standards. But riots and injuries to inmates remained so frequent that Reeves accepted the ACLU's request for him to step in, noting in his ruling that "there is a history of nonfeasance" and a sense of "indifference" by the state and its private contractor, Management and Training Company (MTC), in meeting the terms of the consent decree.

"They were taking their own sweet time," Margaret Winter, an attorney at the ACLU, told BuzzFeed News. "Things weren't changing. So this was to say we're not gonna wait around for five years for this to somehow magically fix itself. People were gonna die."

The ACLU first claimed that conditions at Walnut Grove, which at the time housed offenders between 13 and 22 years old, were unconstitutional in November 2010, when the GEO Group operated the facility. The lawsuit cited a series of violent incidents in recent years: In 2009, for instance, four Walnut Grove youths attacked a 15-year-old after the only guard on duty had stepped out of the cellblock. In 2010 an inmate raped his cellmate, the suit stated. The cellmate pressed a panic button in his cell but it didn't work. There was also a riot in 2010.

In 2012, Just Reeves approved a legal settlement in which the Mississippi Department of Corrections agreed to "transform the facility into one that complies with the United States Constitution" within five years. In his ruling, Reeves called conditions at Walnut Grove a "horror as should be unrealized anywhere in the civilized world." As part of the settlement, the MDOC moved youth offenders into a new facility operated by the state, and Walnut Grove became an adult prison.

Then-Mississippi Department of Corrections Commissioner Chris Epps took the Walnut Grove contract away from the Geo Group and gave it to MTC, a Utah-based firm that grosses more than $500 million in yearly revenue, the third highest in the industry. But violence continued at the facility. There were riots in December 2013 and July 2014. The ACLU hired Eldon Vail, a former Washington state corrections secretary, to inspect the prison.

"The lack of staff supervision is greatly compounded by the fact that the locking mechanisms on the cell doors at Walnut Grove are readily defeated and control of the cell doors is a continuing problem.," Vail said in a statement filed with the court. "Officers at the facility do not always know if an individual cell door is secure."

In August 2014, the ACLU filed a motion asking Reeves to enforce the terms of the settlement and calling for a trial to determine what progress the state had made. Prison officials testified that conditions had improved.

"It's not the same facility I found when I arrived," Lepher Jenkins, who took over as warden in 2014, said at a hearing. In a statement released on Thursday, MTC's Senior Vice President of Corrections, Odie Washington, said that the facility has made "substantial changes" in recent years, including moving mentally ill inmates and high risk offenders to other prisons.

"The state has done everything the courts have asked," Washington said in the statement. "In addition to meeting these significant requirements, MTC has also made numerous improvements to the facility since taking over in 2012 including reinforcing door locks, providing additional staff training, and offering more programs to help rehabilitate offenders."

MDOC commissioner Marshall Fisher said in a statement on Friday: "The court clearly said that we, as defendants, have made 'significant improvements' at Walnut Grove and to blatantly ignore that fact is disingenuous at best. We are not sitting back."

But inmates and court-appointed monitors claimed in testimony that the problems at the facility continued because of gang activity, staffing deficiencies, and malfunctioning cell doors.

Gangs "run amok and control the facility" partly, Reeves stated in his decision, because the facility did not have enough staff members, and the ones they did have were not well trained. And though the state and MTC have made progress to improve training and staffing in recent years, "this is still an area of deficiency contributes to the facility being dangerous for inmates."

One reason staffing has been a problem at Walnut Grove, Reeves wrote, is that the guards are not paid well: the starting salary is $15,602.

"Some officers find an incentive to introduce contraband and participate in other illegal activities as they see them as other sources of income," Reeves wrote.

Mississippi relies on private prisons more than most states. As the state's inmate population rose in the 1990s and 2000s, the state legislature turned parts of its corrections system over to private contractors. In Mississippi, around 20 percent of state inmates are locked up in private prisons, nearly three times the national average.

MTC has expanded its role in Mississippi's prison system in recent years. By 2013, it operated four of the state's five private prisons, overseeing 5,000 inmates, under contracts that added up to around $60 million annually.

The state's ties to private prisons came under fresh scrutiny last year when corrections commissioner Chris Epps was indicted for taking bribes in exchange for private prison contracts. Four of the transactions involved MTC contracts. Epps pleaded guilty earlier this year and is currently awaiting sentencing.