The overcrowded Pedrinhas prison complex in Maranhao state, Brazil, is notorious for gang warfare and riots. About 75 inmates have been killed since 2013, including three who were brutally beheaded during a riot between rival gangs at the hellish penitentiary.

A gory video showing the beheaded bodies of two inmates lying in a pool of blood on the floor was uploaded to YouTube in January 2014.

Pedrinhas Prison
Mario Tama/Getty Images
Pedrinhas Prison
Mario Tama/Getty Images
Pedrinhas Prison
Inmates look out of the barred window of their cellMario Tama/Getty Images
Pedrinhas Prison
Mario Tama/Getty Images

Built for 1,700 inmates, the facility holds more than 2,500. Overcrowding is one of the primary causes of rioting and violence in Brazil's prisons.

Brazil now has the fourth-largest prison population in the world behind the US, Russia and China. The population of those imprisoned in Brazil has quadrupled in the past 20 years to around 550,000 and the country needs at least 200,000 new incarceration spaces.

A vast increase in minor drug arrests, a lack of legal advice for prisoners and government resistance to building new prisons all contribute to overcrowding.

Most detainees cannot afford a lawyer and public defenders are massively over-subscribed. Each public attorney in Sao Paulo's main criminal court is estimated to have about 2,500 cases pending.

Pedrinhas Prison
Female inmates gather in the Pedrinhas Prison ComplexMario Tama/Getty Images
Pedrinhas Prison
Mario Tama/Getty Images
Pedrinhas Prison
An inmate uses a mirror to view visitorsMario Tama/Getty Images
Pedrinhas Prison
Inmates pray before a football match in the Pedrinhas Prison ComplexMario Tama/Getty Images

Pedrinhas has seen efforts from a new state administration and new prison officials which appear to have quelled some of the unrest.

Poor security measures such as broken gates allowed inmates and gang rivals to mix in the open spaces of the complex. Officials say they have conducted an extensive repair programme, allowing law enforcement access and decreasing violence among prisoners.

Pedrinhas Prison
Mario Tama/Getty Images
Pedrinhas Prison
Military Police patrol in the Pedrinhas Prison ComplexMario Tama/Getty Images
Pedrinhas Prison
Military Police keep watch as inmates walk from their cells towards a recreation areaMario Tama/Getty Images
Pedrinhas Prison
Inmates walk from their cells towards a recreation areaMario Tama/Getty Images

Other reforms include a policy of custody hearings and real-time camera feeds.

According to officials there have been no prisoner-on-prisoner killings inside the complex in nearly four months.

Pedrinhas Prison
An inmate paints in the Pedrinhas Prison ComplexMario Tama/Getty Images
Pedrinhas Prison
Inmates' paintings hang in the Pedrinhas Prison ComplexMario Tama/Getty Images
Pedrinhas Prison
An attempted tunnel escape route is cemented overMario Tama/Getty Images