TRIPOLI, Libya — At the height of the Libyan uprising, the country’s prisons were in chaos.

Hundreds of guards had left their posts to help control the streets. Others simply fled for fear of reprisals by a population angry after four decades of oppression.

By Feb. 15 of last year, about a month into the uprising, the doors at most of the country’s prisons and jails began to swing open, allowing thousands of criminals to flee.

According to government officials, about 26,000 criminals — political prisoners were kept in separate facilities and remained in lockdown — were serving time when the escapes began. Almost 200 of those escapees were facing the death penalty for serious crimes, including murder.

“There was panic inside and outside the prisons,” said Dya Adin Badi, who, at the outset of protests last year, was in charge of seven detention facilities stretching from Ras Lanuf through Sirte to Misrata.

“The guards had fled. There was no security, no staff. We didn’t want a riot on our hands.”

In Tripoli, Col. Muammar Gaddafi had already begun to release prisoners in the hope, some claim, that they would join his army ranks. In other areas, instability left wardens with few options.

Badi said angry crowds began to form outside his prisons. Relatives began demanding the release of loved ones, many of whom, Badi said, were facing false or excessive sentences.

“We waited orders from Tripoli, but no word came, so we found our own solution,” he said.

The few staff that remained began releasing inmates 10 at a time. Those facing murder charges were kept in detention for another two days, as much for the protection of the public as for their own safety. But with no security, no staff, no budget and no food, Badi had no choice but to release them too.

Badi said some were reluctant to leave for fear of revenge killings. He recalled one man who begged to stay, but there was no one left to secure the building. His crime had been the murder of two children and their mother. Within two days of his release he was found dead, Badi said.

As the war escalated, it became impossible to tell how many others met the same fate.

Hundreds joined the rebel frontlines. Several climbed the ranks to become commanders. Many were killed in battle. Others simply fled, their whereabouts unknown.

With the proliferation of small arms on Libya’s streets today, the presence of escaped prisoners is a destabilizing force.

Misrata Police Chief Ibrahim Mohammed Alsherikcia said that although these criminals pose one of the biggest threats in the city, old records were destroyed when the Misrata courthouse was bombed and later occupied by Gaddafi forces, so they cannot simply re-arrest former inmates, no matter how serious the offense.

“They are now free criminals and all of them are armed,” he said.

More from GlobalPost in Libya: In-depth series: The rebels after the rebellion

Alsherikcia said that of those who joined the rebel ranks, many were martyred and "redeemed their sins." But others took advantage of the war to gather weapons and continue their criminal activities. Even those who break the law again often go unpunished in a system where militia groups hold more power than police.

In a report released earlier this month, the United Nations expressed serious concerns about Libya’s developing justice system, as well as its ability to contend with past oppression.

“The judicial system suffers from the legacy of being used as a tool of repression,” the report read. “Existing Libyan laws will need to be repealed or amended. … The vast majority of detainees are still held outside the legal framework, despite efforts to centralize detentions.”

In some ways this emerging justice system mirrors that of the former regime, in which security forces “benefited from complete impunity,” the UN report said.

Since the end of the revolution, both ex-rebel militias and police have also administered their own form of justice, also in a “climate of impunity.” While members of Gaddafi forces are hunted down and imprisoned — so far without formal charges or access to legal aid — those who commit offenses from within the revolutionary forces continue to go unpunished.

The UN report did note one significant difference these days. Individuals or independent units, it said, are committing offenses instead of groups operating in a “system of brutality sanctioned by the central government.”

More from GlobalPost in Libya: Exclusive video of Gaddafi's capture

Abdullatef Gadour, a veteran prosecutor in the attorney general’s office who stayed on with the new government, said that while major changes are underway, much of the old judicial system would remain in place. Gadour said the Gaddafi-era laws were essentially adequate and fair.

“One of the few things Gaddafi didn’t destroy was the country’s judicial system,” he said. “Instead he came in through the back door.”

Instead of changing the system, Gaddafi simply created “exceptional courts and laws” for his own purposes, he said. These “closed-door” courts were used to try political prisoners and punish disloyalty to the regime outside of the criminal justice system.

In many cases, prisoners did not see a court at all.

“For every 10 prisoners on record maybe 100 went unnamed,” said Badi, who is now retired from Libya’s prison system. “He recorded this in the same way he kept records of the national budget; he chose which ones to report.”

Today, an estimated 8,000 members of the former regime, many of which are also unlisted and held in unofficial detention centers, face an uncertain future.

Gadour said investigations have begun, trials are being prepared and amendments to the law will take effect once the new constitution is completed. He estimates it will take around five months for the trials to begin.

More from GlobalPost: In Libya's prisons, former rebels exact revenge

Members of Gaddafi’s military will face a military court, while recruits and volunteers who fought on Gaddafi’s frontlines will be tried for murder in a civil court, even if their only victims were fighters, he said.

Killing in combat is not in violation of international laws that regulate warfare. But by national law, Gadour explained, while civilians among Libya’s rebel forces are legally allowed to kill the enemy, those who fought for the old regime will not receive the same concessions.

“Gaddafi troops targeted civilians, while (rebel forces) were defending them. That is the difference,” he said.

Libya’s new justice coordinator, Jamal Bennor, said that, in time, the needed changes to Libya’s justice system would be made. But, he said, it is crucial to activate the security ministries, introduce the new constitution and hold national elections first. In time, justice will be applied equally.

“I think people still trust the law,” he said. “We are still far away from applying the law to many criminal actions, but we are not ignoring these crimes. All offenses will be investigated in time.”