Plagued by riots, murders and escapes, the prolonged crisis in Mexico's overcrowded prisons is being worsened by the infiltration of cartels and the corruption of authorities.
The high-profile escape of the country's most-wanted drugs lord, Joaquin "El Chapo" Guzman in 2015, and a riot last year in a Monterrey penitentiary that left 49 dead, have only underscored the challenges facing the government.
"The crisis comes down to two factors," said Guillermo Zepeda, head of the Jurimetria legal affairs watchdog. "Overcrowding on the one hand, and on the other the penetration of organized crime into penitentiaries."
The government of President Enrique Pena Nieto has vowed to tackle the endemic problem with more infrastructure and equipment, as well as more and better paid prison staff.
In the past year, it has succeeded in reducing the prison population by 30,000, but 58 percent of the country's current 216,831 inmates still live in overcrowded conditions, and more than a third of Mexico's 375 prisons are filled beyond capacity.
Gangs have effective control of cell blocks in some prisons and fight among themselves for control, triggering riots, murders, escapes and clashes.
This year alone there have been shoot-outs, fires and the escape of 29 inmates from prisons in the northeastern state of Tamaulipas. The son of Juan Jose Esparragoza, one of the founders of Guzman's powerful Sinaloa cartel, managed to escape from a prison in the state of Sinaloa.
Images of a "narco-fiesta" went viral on social media this year, showing jailbirds in the western state of Jalisco swigging alcohol, feasting and watching a live concert in which the band played songs hailing the gang boss who had organized the party.
Another video showed inmates being forced by members of a rival gang to clean their cells while dressed in women's lingerie.
Just a few days ago, police found guns and a tunnel in another prison in Tamaulipas where 80 percent of the inmates are members of the Gulf Cartel.
Memories are still fresh of Guzman's spectacular escape from a maximum security penitentiary two years ago, ducking down a tunnel under the very noses of his guards and staying on the run for months. That was the second time he had busted out, having carried out another high-profile jailbreak in 2001.
Those scenes, as well as the gang brawl that killed 49 prisoners in Monterrey's Topo Chico prison last year, are made possible by "the corruption inside the system," said Catalina Perez of the Center for Research and Teaching in Economics. "There is a lot of corruption which no one is dealing with," she said.
"You end up with some inmates paying for luxury cells and whatever else they want, while the poorer ones wind up cleaning the toilets," she told AFP.
The National Human Rights Commission (CNDH) in May reiterated its concern over what it called the worsening state of gangs running or partially controlling prisons, "in the face of a growing number of inmates linked to organized crime or with higher economic means."
Almost half of the inmates in federal penitentiaries, and 30 percent of those in state jails, are held in preventive custody, waiting to be tried or sentenced. In many cases, they face charges for minor crimes, such as robbery without violence.
"These people have few financial resources and have only been accused of minor crimes, said Perez.
She said Mexico has to decide what function its prisons serve: "If we are going to use them for people caught with small amounts of illegal substances or to reassimilate (into society) those who committed the worst crimes."
In June last year, Congress passed a law that gave the greenlight to punishments that would allow reparation of damage and community work rather than jail time.
It aims to reassimilate offenders and take the pressure of the prisons, but its implementation on the ground has been slow.
"Now we have to demand that the authorities carry out the work in keeping with the law, something which is not happening now," said Angelica de la Pena, from the left-leaning Party of the Democratic Revolution (PRD), who heads the upper house's human rights commission.
Civil rights groups, for their part, are concerned that society has not been educated to be more accepting of those who have served time.
"If people coming out of jail cannot find work, are discriminated against, and are notorious in their own neighborhoods, then it will be a never-ending cycle," said Consuelo Banuelos, head of Promotion for Peace, a group working to rehabilitate prisoners in society.