The Senate just barely advanced legislation on Tuesday to reauthorize a key counterterrorism surveillance tool after several Republicans and Democrats demanded more privacy protections for U.S. citizens.

The bill, a six-year reauthorization of the Section 702 of the Foreign Intelligence Surveillance Act, passed the House last week, but it was less clear whether the Senate would agree to end debate on the bill on Tuesday.

Three-fifths of voting senators were needed to end debate and head toward a final vote on the bill, and the Senate just barely found the votes. The Senate voted 60-38 to advance the legislation.

The vote, which was held open for almost an hour and a half, was stuck at 58-38 for several minutes as senators lobbied the remaining votes for and against the bill.

Sen. John Kennedy, R-La., was one of those senators, and he ultimately voted in favor of the bill. Another was Sen. Claire McCaskill, D-Mo., and she also voted for it.

The spying tool allows intelligence officials to search communications of non-citizens outside of the U.S.

Senate Minority Leader Chuck Schumer, D-N.Y., led Democrats in opposition to the bill. Schumer said the six-year length of the reauthorization is “too much,” and should include longer debate and an opportunity to make changes.

“We ought to have some amendments and some discussion,” Schumer said.

The bill includes moderate reforms authored by both the House Intelligence and Judiciary Committees and in league with the Senate Intelligence Committee. Those reforms proved to be just enough to win the bipartisan support it needed to advance.

Proponents say the changes will bolster privacy protections by adding a new requirement for intelligence agencies to obtain search warrants to search communications, and new congressional oversight of the kinds of searches made by the government. It also limits the use of the surveillance authority so fewer Americans are caught up in the searches, and requires reforms to the way intelligence agencies search the contents of electric communications beyond the sender information.

Before the vote, a bipartisan group of lawmakers want more stringent requirements for intelligence officials to seek warrants before examining communication from Americans who are swept up in surveillance of foreigners.

“Many innocent Americans get caught up in that,” Sen. Rand Paul, R-Ky., said before the vote. “Should the government be allowed to search this database to prosecute you for not paying your taxes or a minor marijuana violation? It’s gathered lawfully — for foreigners.”

Opponents of the bill said there is no need to pass legislation immediately because the intelligence community actually has the authority to use the spy tool until the end of April.

But the bipartisan leaders of the Senate Intelligence Committee, as well as Judiciary Chairman Chuck Grassley, R-Iowa, said the bill needed to pass to ensure the U.S. has access to the intelligence needed to fight off threats to the country, and that its reforms should ease the concerns of opponents.

“This bill provides the intelligence community and law enforcement with the right tools, but it also minds the civil liberties and the privacy protections that our constitution requires, especially given the ever changing technological landscape," he said.