When 67 senators voted June 2 to end NSA cellphone bulk data collection, and President Obama signed the law, they were saying—finally—that Edward Snowden was right. When he revealed the once-secret fact that the records of all cellphone calls by Americans were collected and stored by the NSA, his hope was to “trigger a debate” over privacy and civil liberties, as he told Glenn Greenwald when he went public in June 2013. He has succeeded.

But Snowden was called “a traitor” and charged by the Obama Justice Department with violating the Espionage Act. “Espionage,” of course, is defined as giving secrets to the enemy, but Snowden gave secrets to the American people. Now the elected representatives of the people have spoken—and they should be saying “Thank you” to Edward Snowden.

Under the new legislation, the government can no longer collect and hold information about Americans’ cellphone calls—the numbers they called and the time and duration of the call—information the Stasi and the KGB never dreamed of. The phone companies will now hold that information, and if the government wants to see who someone has been calling, they will have to get a court order. And the Foreign Intelligence Surveillance Court will be curtailed—instead of making its decisions in secret without an adversary proceeding, it will permit outside advocates to argue against the government and declassify some of its most important decisions.

Obama in 2014 argued that Snowden should not be thanked for provoking the debate over national security powers. He said he was the one who deserved credit: “I indicated in a speech at the National Defense University last May [2013] that we needed a more robust public discussion about the balance between security and liberty.” He criticized Snowden for “the sensational way in which these disclosures have come out” which “shed more heat than light, while revealing methods to our adversaries.”

Snowden’s critics have argued that, if he’s sincere about his actions, he should return to the United States and make his case before a jury of his peers. But under the Espionage Act, testimony by a defendant about his intent is not permitted—the only question is whether information that could harm the United States was released. There are no whistleblower protections in the Espionage Act. If Snowden were on trial and said, “Let me explain why I did this,” the prosecution would say, “Objection—irrelevant” and the judge would say, “Sustained”—and Snowden would be convicted.

It was always an outrage that Snowden was charged under the Espionage Act, and the actions by Congress and the president this week make the charge even more absurd. Instead of punishing Edward Snowden, Congress and the president ought to be thanking him. And so should the American people, who have just regained some of their liberty and privacy because of his work.