After serving more than twenty years in a maximum security New York state prison for a murder he did not commit, David Ranta walked free on Friday. “To say that I’m sorry for what you have endured will be an understatement and grossly inadequate, but I say it to you anyway,” said State Supreme Court Justice Miriam Cyrulnik. “Sir, you are a free man.”

Ranta did not win an appeal. He was not freed as a result of DNA testing or work by an innocence project. Rather, his exoneration was overseen by the Kings County District Attorney’s Office in Brooklyn—the very same office that vigorously prosecuted him and put him behind bars in 1991.

In 2011 District Attorney Charles Hynes established a special unit within his office to evaluate claims of innocence from people his office had prosecuted. This unit was also tasked with implementing reforms to prevent such mistakes going forward. Hynes’s is the newest of about a half-dozen of these “conviction integrity units,” the largest and most established of which are in Dallas, Manhattan, and Santa Clara, California.

This is an outside-the-box idea. The U.S. criminal justice system is adversarial, set up to pit prosecutors against defense attorneys. For centuries it has been defense attorneys—and organizations where they work, such as innocence projects—that have fought prosecutors to win their clients’ freedom. Now prosecutors are acting on both sides of the system: locking people up, and then, if there has been an error, letting those same people out.

In some ways, this is nothing new. “Even before anyone had the idea of a conviction integrity unit—if you get a bona fide claim of innocence or newly discovered evidence, there’s a whole set of rules that have been around for a long time,” says Nancy Hoppock, executive director of NYU’s Center on the Administration of Criminal Law, which runs the Conviction Integrity Project. “We’d all lose our license if we didn’t bring forward that newly discovered evidence.” A good prosecutor is an ethical prosecutor—committed to doing justice, not just to winning convictions—and as new evidence arises, prosecutors are legally and ethically obligated to vacate convictions of the innocent. Still, Hoppock concedes, “Laziness and inefficiency and messiness” often prevent overworked prosecutors from pursuing innocence claims or investigating new evidence.

When prosecutors do pursue innocence claims, the exonerations happen quietly, without press or fanfare. “Most lawyers and law enforcement professionals have no interest in drawing attention to the tragic errors in their own line of work, even though they may do what they can to correct them,” says University of Michigan Law Professor Samuel Gross. “What’s the value of having a conviction integrity unit? Doing it more systematically. And doing it publicly. If prosecutors themselves start owning up to the issue, they would be more effective at preventing cases and more effective at catching them.”

These units typically have a dual role. On the “front end,” they work with prosecutors and police to prevent wrongful convictions. This could mean offering specialized training in wrongful convictions; working with the police to institute best practices, such as double-blind sequential lineups, which have been shown to reduce eyewitness misidentification; or requiring prosecutors to use a series of checklists throughout the investigation process. As Manhattan District Attorney Cyrus Vance described it in a 2011 speech, these checklists help “anticipate those issues that might lead to wrongful convictions, while strengthening those cases that are brought to trial.”

On the “back end,” the units review claims of innocence from defendants convicted by their office. Credible claims are re-investigated and, if they are compelling, the district attorney attempts to secure exonerations.

The idea of a dedicated conviction integrity unit originates with Dallas District Attorney Craig Watkins, who in 2007 won an upset victory for the post after campaigning as a “different kind of prosecutor.” “I lock them up if they’re guilty,” he told the New York Times after he took office.

As exonerations stack up, so does public awareness of systemic flaws that lead to wrongful convictions.

Watkins was setting himself apart from what he has called a “convict at all costs” mentality among his predecessors, who oversaw convictions of at least a dozen innocent people and then threw up every possible legal roadblock to prevent the prisoners airing their claims of innocence. “Dallas County fell in line with most prosecuting authorities that viewed claims of actual innocence . . . with skepticism, cynicism, and, sometimes, open disdain,” writes Mike Ware, an attorney with Watkins’s office, in a recent legal journal article about his experiences. “Even now, more than twenty years after the first DNA exoneration . . . prosecutors routinely argue, often successfully, that a convicted defendant, even if innocent, does not have the legal right to conclusively prove his or her innocence.”

Previous Dallas district attorneys treated these exonerations as embarrassments and aberrations, to be downplayed and ignored. Watkins took a different tack, committing to learning from past mistakes, applying these lessons to his practice going forward, and actively seeking out injustices to right. He convinced county officials to provide $450,000 for a new program and hired two lawyers, an investigator, and a paralegal to re-investigate credible claims of innocence. The conviction integrity unit, which has in five years overseen more than twenty exonerations, has made Watkins into something of a celebrity. He’s been profiled in several national newspapers and was even the star of a six-part Discovery Channel series called Dallas DNA.

All of which provides fodder for criticism of both Watkins and conviction integrity units more generally: that they are largely publicity stunts, hobbled by conflicts of interest and motivated by politics.

“One of the things that is most peculiar about the American system of criminal justice is that prosecutors are elected political officials whose position depends not on their performance within a professional organization but on their ability to get people to vote for them in November,” says Gross. “Are we shocked to find out an elected official is acting like a politician?”

As exonerations stack up—there have been more than a thousand since 1989, according to the National Registry of Exonerations, which Gross runs—so does public awareness of systemic flaws that lead to wrongful convictions. So for district attorneys, attempts to publicly “fix the system” are good politics.

Prosecutors know this. A group of them from around the country wrote an 82-page report [PDF] on best practices for setting up these units, and the rationale for doing so: “As more individuals are exonerated for crimes that they did not commit . . . the public—which includes jurors, witnesses, and judges—will begin to lose confidence in prosecutors and view them as responsible,” the report says. “To combat this misperception, prosecutors . . . can take affirmative steps to safeguard and improve the integrity of their cases, thereby shaping the narrative on wrongful convictions.”

In addition to serving as political vehicles, conviction integrity units present possible conflicts of interest. Watkins and Vance are new to their jobs, so they are investigating the mistakes of their predecessors. But what if those predecessors are friends and confidants? And what happens when, inevitably, a prosecutor is called upon to investigate himself?

This is the uncomfortable position that Hynes finds himself in. Hynes was elected as Kings County district attorney in 1989 and made the conviction of David Ranta a centerpiece of his first term. The prosecution’s case against Ranta, for the 1990 murder of a prominent Hasidic rabbi and Holocaust survivor, was riddled with holes, misconduct, and errors. A detective coached witnesses to lie and took prisoners out of jail to eat at restaurants. Hynes personally gave a drastically reduced sentence to an armed robber turned jailhouse snitch who claimed Ranta had committed the murder.

And now that Ranta’s is one of the first exonerations of Hynes’s conviction integrity unit, Hynes seems to be occupying that tense middle ground of doing the right thing while trying to save face. The New York Times reports that John O’Mara, who oversees the Brooklyn conviction integrity unit, “offered no regrets, noting that he was not involved in the original case. And he suggested, without offering evidence, that Mr. Ranta still might have committed the crime.”

In a recent piece for this magazine, I wrote about the North Carolina Innocence Inquiry Commission, an independent state agency that evaluates claims of innocence. The Commission avoids the pitfalls of politics and conflicts of interest by remaining a neutral party with no stake in any of the cases they investigate—except to find the truth. Organizations such as this one, and innocence projects, are essential thorns in the side of a system that’s not working.

But conviction integrity units can at least ensure that the system begins to work better. Despite its flaws, it’s the system we have. “Prosecutors and police are the work horses of the criminal justice system,” says Gross. “They see all of the cases, they are more likely than anybody to run across new evidence that a defendant is innocent, and they probably get more requests for help from wrongfully convicted defendants than everybody else in the country combined.” Thus prosecutors are in a better position than anyone to reopen cases—and to prevent wrongful convictions from happening in the first place.

So “is there a conflict of interest?” Gross asks. “Sure. Will that impact investigations of cases? It may very well. I still think it’s a very good idea.” Ranta must have thought so too, on his first night of freedom in over two decades.