WASHINGTON (AP) – The Obama administration said Thursday it will phase out its contracts with private prisons, affecting thousands of federal inmates.

The decision announced by the Justice Department comes after an audit this month found that private facilities have more safety and security problems than the government-run prisons. The federal prison population has been declining due to changes in sentencing policies over the past three years, reducing the need for private prisons.

“Private prisons served an important role during a difficult period, but time has shown that they compare poorly to our own Bureau facilities,” Deputy Attorney General Sally Yates wrote in a memo to the acting director of the Federal Bureau of Prisons. As private prison contracts come to an end, the bureau is not to renew the contract or it should at least “substantially” reduce its scope, Yates wrote.

The federal government started to rely on private prisons in the late 1990s due to overcrowding. As of December 2015, private prisons held more than 22,000 prisoners – or about 12 percent of the total federal prison population, according to an inspector general report released earlier this month. Many of the inmates were being held on immigration offenses, the audit said.

The private prisons are operated by three private companies – Corrections Corporation of America, GEO Group Inc., and Management and Training Corp. Shares of the two publicly-traded prison operators plunged in midday trading. Corrections Corp. stock dropped $13.22, or 48.6 percent, to $14 and Geo Group tumbled $13.80, or 42.7 percent, to $18.49. Both companies get about half their revenue from the federal government.