A debate over a controversial law that gives the government broad powers to spy on foreigners purposefully and Americans incidentally briefly rocked both the White House and Capitol Hill on Thursday after a disruptive tweet by President Donald Trump.

A section of the Foreign Intelligence Surveillance Act (FISA), Section 702, allows US intelligence agencies to collect the email communications of foreigners living abroad in order to obtain information about potential threats against the United States. But sometimes intelligence agencies sweep up emails sent by or to Americans, and that worries citizens and policymakers alike who care about their privacy.

It also evidently worries President Trump.

On Thursday morning, as the House of Representatives was about to begin deliberations on an amendment to the law that would help safeguard Americans’ privacy by requiring government officials to request a warrant before looking at information collected from emails by US intelligence agencies — the president posted a tweet criticizing the law:

“House votes on controversial FISA ACT today.” This is the act that may have been used, with the help of the discredited and phony Dossier, to so badly surveil and abuse the Trump Campaign by the previous administration and others? — Donald J. Trump (@realDonaldTrump) January 11, 2018

Panicked Republicans considered pulling the bill because they thought the president was against it. But about 90 minutes after his first tweet, Trump posted a follow-up tweet that seemed to walk back his opposition to the law:

With that being said, I have personally directed the fix to the unmasking process since taking office and today’s vote is about foreign surveillance of foreign bad guys on foreign land. We need it! Get smart! — Donald J. Trump (@realDonaldTrump) January 11, 2018

The amendment ultimately didn’t pass, but the House did vote to reauthorize the law for another six years by a 256 to 164 margin.

Thursday’s drama is just the latest moment in the years-long controversy over the US government’s ability to collect, store, and even read the emails involving American citizens and residents because of FISA’s Section 702.

Here’s a brief guide on what Section 702 lets America’s intelligence agencies do — and why it’s long been a sensitive issue for Americans in and out of government.

Section 702 targets foreigners’ emails — but there’s a catch

Section 702 doesn’t allow intentional surveillance targeting of Americans; rather, targeting of “accounts whose owners are reasonably believed to be foreigners outside of the United States,” Michael Hayden, a former director of the CIA and NSA, told me.

The law is intended to collect information that could potentially stop terrorist attacks by foreigners against the United States, but sometimes the spying programs scoop up Americans’ emails and information along with it.

“Most of the world’s internet traffic passes through portals inside the United States,” said Todd Rosenblum, a top intelligence official at the Department of Homeland Security from 2009 to 2011. Because of that, it’s difficult not to unintentionally collect information from or about US citizens and residents.

Critics believe that violates Americans’ Fourth Amendment right against unreasonable searches and seizures.

The FISA court is supposed to be the legal check on the government’s surveillance powers. Made up of 11 judges, the court is who ultimately decides whether or not intelligence officials can look at email content or other data as part of a national security investigation.

Proponents argue that this court serves as a sufficient check on the government’s powers; critics, on the other hand, say the court provides nothing more than a rubber-stamp for whatever the intelligence agencies ask for.

The debate over the FISA court is just one of the many controversies surrounding Section 702. At the core, the question is whether the government should prioritize the security of the American people, or their privacy.

The privacy versus security battle continues

Rep. Zoe Lofgren (D-CA) co-sponsored the failed amendment to add new safeguards to Section 702, along with Rep. Justin Amash (R-MI).

“Because of the architecture of the internet, we are collecting vast amounts of data,” Lofgren told me. “Your phone calls, your emails, your text messages, and video messages. And under Section 702 you can search that for Americans and for crimes that have nothing to do with terrorism.”

Privacy advocates also point to the potential for the law to be abused. “Section 702 could too easily be a tool to target government critics, immigrants, and vulnerable communities,” said Neema Singh Guliani, legislative director at the American Civil Liberties Union.

Such cases have happened. In May 2015, for instance, FBI agents arrested a man named Xiaoxing Xi, a Chinese-American physics professor at Temple University. The government claimed he was a Chinese spy after looking at his communications with the FISA Court’s approval. The government dropped the charges four months later because it appeared he was merely contacting colleagues in China. Xi is now working with the ACLU to sue for damages.

Hayden and many others in the intelligence community have a different view of Section 702. On October 23, Hayden and 15 other national security professionals — including former CIA Director John Brennan and former Director of National Intelligence James Clapper — signed a letter to congressional leaders urging them to reauthorize the email-collection provision.

“There is no substitute for Section 702,” they wrote. “It is the most effective mechanism to protect the US from the very large number of real threats that use American email and Internet services.”

The debate over Section 702 now moves to the Senate, where it will likely not spark the same level of controversy as it did in the House vote on Thursday. So far, senators from both parties have signaled they will reauthorize Section 702 without any additional reforms to ensure greater privacy. But the wider debate about striking the right balance between citizen privacy and security is sure to continue.