The National Security Agency has said that it has begun destroying hundreds of millions of records of phone calls and texts after it found that it had no authority to receive some of those records, according to the New York Times.

The agency said in a statement Thursday that it began purging the records on May 23 after “NSA analysts noted technical irregularities in some data received from telecommunications service providers.”

Those “irregularities” led the NSA to realize the entire database containing records of metadata—details of calls and texts that include the people involved in them and when they were made or sent—obtained from American telecommunication companies since 2015 was contaminated with files the agency was not allowed to collect.

After the leaks by Edward Snowden revealed that the NSA had been collecting American calling records indiscriminately, Congress replaced the program authorizing that data collection with the Freedom Act, which stipulates that the agency can only collect specific records related to those suspected of having links to terrorism, as well as the suspects’ contacts. The NSA has collected hundreds of millions of these records, according to the Times.

A representative for the NSA told the Times that one or more telecommunications providers accidentally responded to court orders requesting records with call and text logs that included numbers of those not in contact with the suspects.

That mistake then led the agency to gather call information related to people it had no authority to collect records of. The representative said the agency determined it would be too difficult to purge those unauthorized records from the database, and as a result the agency has decided to delete all of them.