FBI Director James Comey testified before the House Judiciary Committee in September. (Pablo Martinez Monsivais / AP)

Crafting a compelling and intricate story is a challenge. The key, I learned as author of three popular legal thrillers, is getting the right mix of character development, suspense, atmosphere and, above all, an ending no one can see coming. You need an active—and sometimes jaded—imagination to pull off the trick.

Still, even in my most febrile writer’s dreams, I couldn’t have devised a plotline approaching what happened the morning of Oct. 28, when FBI Director James Comey sent a terse, 166-word letter to the chairs of eight congressional committees, disclosing that the bureau had discovered additional emails that required it to take further “appropriate investigative steps” regarding Hillary Clinton’s use of a private internet server during her tenure as secretary of state. Only last July, Comey had broken the hearts of Republicans everywhere as he told Congress and the world that the email probe had been completed and Clinton would not be prosecuted.

So forget WikiLeaks, and forget Clinton’s speeches to Goldman Sachs and the behind-the-scenes machinations of John Podesta: Comey’s letter was the ultimate October surprise, at once breathing new life into the seemingly moribund Trump campaign and triggering shockwaves of anxiety and spasms of political bed-wetting among Democrats.

And then came another, even more improbable twist: The new emails had been found on a laptop computer owned by none other than Anthony Weiner, the disgraced former New York congressman who just happens to be the estranged husband of top Clinton aide and confidante Huma Abedin. The emails had been uncovered during the course of a separate investigation into sexual messages Weiner had dispatched to a 15-year-old North Carolina girl.

If I had pitched a screenplay like that—even to the edgy Coen brothers—the concept would have been shot down as too implausible and incapable (in the argot of the trade) of generating the required “suspension of disbelief” needed to sustain viewer interest. I can just see the rejection note now, telling me that no one would buy into a culprit named Weiner with a penchant for circulating dick pics online. No one.

Except this plotline isn’t fiction. It’s fact, and it has the potential to alter the outcome of the presidential election and, with it, our collective future.

So I, along with sundry other legal and political commentators, have to ask: Why did Comey write his letter, and was his decision to do so a clear break with long-standing FBI and Justice Department policies — and possibly itself a violation of law? Even more fundamentally, I have to ask what the whole stomach-turning tale says about the state of American democracy.

Unfortunately, coming up with answers isn’t easy. For starters, only Comey knows the full extent of his motives. In his letter to Congress, the director wrote merely that his Oct. 28 letter was sent to “supplement my previous testimony,” given before the House Oversight Committee in July and House Judiciary Committee in September.

In a memo circulated to FBI staff the afternoon of Oct. 28, Comey elaborated:

Of course, we don’t ordinarily tell Congress about ongoing investigations, but here I feel an obligation to do so given that I testified repeatedly in recent months that our investigation was completed. I also think it would be misleading to the American people were we not to supplement the record. At the same time, however, given that we don’t know the significance of this newly discovered collection of emails, I don’t want to create a misleading impression. In trying to strike that balance, in a brief letter and in the middle of an election season, there is significant risk of being misunderstood, but I wanted you to hear directly from me about it.

Comey is an imposing physical figure. A towering 6 feet 8 inches tall, he has a blunt, no-nonsense speaking style and a stern countenance. He also has a reputation for doing the right thing, no matter the consequences and who gets pissed off.

Comey was the guy who in 2004, as a deputy attorney general, rushed to the hospital bed of his seriously ill boss, John Ashcroft, and stood up to then-White House counsel Alberto Gonzales and George W. Bush chief of staff Andrew Card as they attempted to persuade the weakened Ashcroft to certify aspects of the Bush administration’s domestic surveillance program that the Justice Department had deemed unconstitutional. If cast in a classic Hollywood movie for the gesture, you’d think of Gary Cooper, standing tall and alone as the quintessential lawman in “High Noon.”

But dig a little deeper into his background and a more nuanced and far less flattering picture of Comey emerges as a GOP hitman. Early in his government career, Comey worked as a special counsel for the Senate Whitewater Committee, investigating Bill and Hillary Clinton’s involvement in a set of shady Arkansas real-estate investments from the 1970s and ’80s. Later, as a federal prosecutor, he supervised a probe of Bill Clinton’s 2001 pardon of financier Marc Rich, who had been indicted for tax evasion and illegally trading with Iran and subsequently fled the country.

In addition, Comey’s resume includes important and highly lucrative private-sector stints of a decidedly right-wing bent. As MarketWatch columnist Brett Arends catalogued in a post Wednesday, Comey raked in millions a year in salary and stock bonuses as an attorney working on behalf of defense-contractor giant Lockheed Martin, and Bridgewater Associates, known as the country’s largest hedge fund. For a time, he held a seat on the board of HSBC, the global investment bank that was hit in March 2013 with a $1.3 billion fine for international money laundering.

Initially appointed to the Justice Department by the Bush-Cheney administration in 2003, Comey was nominated by President Obama in June 2013 to become FBI director. He was confirmed a month later by the Senate on a 93-1 vote, with Rand Paul, R-Ky., the lone dissenter.

Among his public declarations since assuming the top post that September, Comey has claimed that the Black Lives Matter movement and the “Ferguson effect” (referring to the impact of street protests against police shootings and viral videos of police misconduct) are responsible for the recent uptick in violent crime in some cities. His position has drawn sharp criticism from the Obama administration, as well as the broader civil rights community.

So, was Comey’s Oct. 28 letter the result of his pent-up urge to get back finally at the Clintons and the Democratic establishment? The highly respected Guardian columnist Spencer Ackerman asserted in an article published Wednesday that the FBI has become “Trumpland,” populated by field agents and other officials rankled over Comey’s initial decision not to seek criminal charges against Hillary Clinton.

Those looking for bias in Comey’s letter might also point to the bureau’s release Tuesday of a 129-page archive from the Marc Rich investigation and pardon. Why make such documents public, Clinton backers have asked, just days before voters head to the polls if not to place a thumb on the electoral scale?

Still, it’s not easy to come to any definite conclusions about Comey’s intentions. Ever since Attorney General Loretta Lynch’s fateful encounter with Bill Clinton at the Phoenix airport in early July, Lynch has encountered demands that she recuse herself from the email controversy. As a result, Comey has been forced to become the public face of justice on the issue and take on the task of announcing the results of the long federal inquiry into the email controversy.

He remains that public face to this day.

To be sure, in revealing that the bureau is once again looking into Hillary Clinton’s emails, Comey has violated long-standing Justice Department protocols that instruct federal prosecutors to remain silent about ongoing investigations within 60 days of an election.

But to be fair, Comey has been caught between the proverbial rock and hard place. By announcing that the email hunt is once again on, he has entered the forbidden arena of partisan politics, condemned by Democrats for boosting Donald Trump’s fading prospects at the last possible minute. On the other hand, remaining silent until after the election would also have had profound political ramifications, especially if Hillary wins, sparking outrage on the Republican right over yet another Clinton cover-up.

In the end, the biggest casualty in the entire tangled and interminable scandal may be democracy itself. We’ve been reduced to a pulp-fiction version of constitutional governance. The head of the nation’s pre-eminent law enforcement agency, his hand forced by an online sex addict named Weiner, may determine the outcome of one of the most consequential presidential elections in our history.

That’s something I, for one, never saw coming.