Image copyright Win McNamee Image caption James Comey faces criticism from the right and the left

Shortly before the election, the FBI has become a lightning rod for controversy. During this time, the bureau has gone through the most public humiliation in its history.

On Sunday, FBI Director James Comey told US lawmakers that no charges would be filed against Hillary Clinton, the Democratic nominee, for her handling of classified information.

He was trying to put an end to rumours about what might happen to her - and restore the reputation of the bureau.

He has a lot of work to do.

The tone of his announcement on Sunday was measured.

But the timing, two days before the election, made him and his colleagues seem panicked - and worried about their own future.

Image copyright Chip Somodevilla Image caption Donald Trump welcomed the FBI's announcement about the investigation

However measured, these were the words of an FBI director in damage-control mode. Comey was trying to make up for past mistakes - and contain fallout from his earlier remarks.

On 28 October, he sent a letter to several Congressional committees, informing them that investigators had come across new information that could involve Clinton's use of a private server.

That letter was a bombshell, lobbed in the midst of an intensely savage presidential campaign - in a nation ripped apart by partisan politics.

It was followed by leaks, rumours and ferocious attacks by staffers from both campaigns, Democratic and Republican - many involving the bureau.

Even those who love the bureau and admire its director have been troubled by the way it has gotten caught up in politics.

In some accounts at least, the FBI has been cast as a place full of Trump supporters who are trying to sabotage Clinton's campaign. But the assumptions about their political views may be misguided.

Image copyright Justin Sullivan Image caption Hillary Clinton said that the FBI's actions were "unprecedented"

Some people at the FBI like Trump. But many do not. In a broader sense, people in the intelligence community have been wary of him.

One of them told me that if Trump were elected - and appoints one of his key advisors, Michael Flynn to a high-level intelligence position - there will be a "mass exodus" of officers and analysts.

Regardless of their politics, the people who work at the bureau still support Comey. He remains popular. But they also wish the problems would go away - and that the election would be over.

The problems date back to July. Back then Comey told Congress he did not believe Clinton should face prosecution for mishandling classified information.

Then investigators started to gather information about a separate case, involving Anthony Weiner, a former US congressman who's married to Huma Abedin, an aide to Clinton. (Weiner is now separated from Abedin.)

The investigators were trying to find out information about Weiner and illicit messages he apparently sent to an underage girl. During their search, they came across material they thought deserved a closer look.

Comey wanted to make the process as transparent as possible, say his friends and relatives. That's why he told Congress about the developments.

Image copyright Chip Somodevilla Image caption Huma Abedin, a close aide to Clinton, was caught up in controversy

"He's a very decent man," said Stephen Saltzburg, a former senior justice department official. "But I think he made a mistake."

"Comey dug himself into a hole," said Spike Bowman, a former assistant general counsel at the FBI. "He's trying to figure out a way to get out of it."

Many people said they were glad Comey chose to inform Congress about the developments in the investigation as they happened. They thought that voters should know about them.

Others said that releasing information about the investigation violated justice department rules about not interfering in an election.

"Days before the election, public discussion is dominated by actions that the FBI director took. That is improper," said Steven Aftergood, the director of the Project on Government Secrecy for the Federation of American Scientists.

Aftergood said that Comey may have had good intentions. Still, said Aftergood: "His actions were destructive."

Comey knows that, and has been scrambling to minimise the destruction. Investigators at the FBI sifted through the additional emails - vast amounts of material - in a surprisingly short time.

Then Comey made his latest announcement. Rumours are still flying, though, and voters are trying to make sense of things.

However you see Comey or the bureau - or his efforts to salvage their reputation - one thing is certain. After Election Day, regardless of the outcome, scrutiny of the FBI and its director will continue.

So will the controversy.

Follow @Tara_Mckelvey on Twitter.