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.

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 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.

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.