President Barack Obama on Thursday signed a bill barring Nazi war criminals from collecting retirement benefits after an Associated Press investigation revealed that dozens of former Third Reich soldiers were doing so.

The AP’s two-year investigation found that the former Nazis — which included SS guards who patrolled camps where Jews were detained and a rocket scientist who worked on developing a rocket used to attack London — had received millions of dollars in U.S. Social Security benefits after the government forced them to leave the country, the news service reported.

The No Social Security for Nazis Act halts benefit payments to those who have lost their U.S. citizenship as a result of their participation in the Nazi regime during World War II, where previously only deportation prompted the termination of payments.

The AP reported that since 1979, at least 38 of 66 suspects forced to leave the country continued to receive their benefit payments. Many of them also lied about their pasts to become U.S. citizens in the first place.

One former Nazis who was denaturalized fled to Germany as part of a deal with the U.S., where he continued receiving $1,500 in benefits each month, the AP reported. Dozens of these former Nazis took advantage of the loophole, created by the Department of Justice to use as leverage to deport future suspected Nazis.