The US immigration system was designed to track who comes into the country, not who leaves. For more than two decades, authorities have been trying to find an effective way to keep tabs on departing foreigners—and those who overstay their visas.

US Customs and Border Protection (CBP) now says it’s found a solution: facial recognition. It expects to be able to scan 97% of commercial passengers within the next four years, according to a report released by the Department of Homeland Security today.

Here’s how the system works:

Passengers approach cameras installed at airport gates to have their pictures taken before boarding their plane. Those images are then used to identify the passenger using photos from visa and passport applications or customs screenings upon entering the US. If a picture matches information on file, the system creates an exit record. If it doesn’t, CBP officials look into it. (Visa overstayers can be barred from re-entering the US for up to 10 years.)

By last fall, cameras were screening passengers at 15 different US airports. The system, tested on more than 15,000 flights, identified 7,000 travelers who overstayed visas, according to the agency. CBP calculates that 666,582 passengers who arrived by plane or boat overstayed visas in fiscal 2018. For the past few years, overstayers have represented a bigger share of undocumented immigrants than those who enter the country illegally.

Critics say this CBP use of artificial intelligence is an invasion to privacy. They worry about how the information could be used. CBP says the images are encrypted and that it only keeps them for a brief period of time.

The camera setup eventually could replace the current system, which relies on departing airline flight manifests. Of course, the new system doesn’t help with tracking who leaves by land. Canada shares information of who comes in from the US with CBP. When it comes to departures through Mexico, officials often only become aware someone left the US when that person tries to come back in. “The majority of those travelers are frequent border crossers and CBP is able to close a previous arrival when recording a new arrival,” the agency said in its report.

That could change: CBP says it’s starting to test facial recognition to identify people driving through a land border crossing in South Texas.