Corrections Corporation of America (NYSE: CXW) has owned and operated Cibola County Correctional Facility in Milan, New Mexico since 1998. The largest private prison company in the U.S., CCA ran the 1,200-bed prison under a contract with the Federal Bureau of Prisons and provided 300 jobs to residents of Milan, population 3,245, and nearby Grants. But at the end of July, those 300 workers got some bad news: the bureau was terminating its contract with CCA, and with it, their jobs.

It was an unusual move: BOP has terminated contracts with private prisons early just three times in the last decade, according to a Nation investigation. But it wasn’t an unexpected step: the announcement followed years of government warnings about inadequate health care at the facility, as well as three inmate deaths. In January 2015, the government warned CCA that the facility could be closed if medical care wasn’t improved by April. On July 29, word came down from the BOP: the facility would be closed for good at the end of October, years ahead of the contract’s 2020 end date.

Then in August, the bureau announced it would phase out its use of private prisons entirely as current contracts with providers came to an end, citing a shrinking prisoner population and the desire to “ensure consistency in safety, security and rehabilitation services.”

The same day, CCA’s stock price plummeted 35 percent. Shortly after, the company changed its name to CoreCivic following 23 years operating as Corrections Corporation of America.

But on Oct. 27, just as the last of the federal prisoners were being moved out of the Cibola County facility, Immigrations and Customs Enforcement (ICE), which is running out of places to hold a growing immigrant detention population, stepped in. The agency, which is part of the Department of Homeland Security, signed a five-year contract with CoreCivic to run the Cibola County Correctional Facility as an immigrant detention center.

The same pattern repeated itself on Dec. 14, when CoreCivic announced that ICE had signed a contract to use their 1,100-bed Youngstown, Ohio facility as an immigrant detention center after CoreCivic’s contract to run the facility on behalf of the U.S. Marshals Service ends in March.

The immigrant detention population has grown in recent months. In November, the Department of Homeland Security said it was detaining 41,000 people at its immigrant detention centers, up from an average of 31,000 to 34,000 over the last decade. At the same time, the federal prison population shrank for the first time ever in 2015, as states and the federal government are seeking to roll back mass incarceration in the U.S., which has resulted in a country with just 5 percent of the world’s population accounting for a quarter of the world’s prisoners.

Looking at that changing math, CoreCivic is transforming its facilities from prisons to immigrant detention centers. The strategy started under President Obama, who deported more people than any president ever, and will surely continue under President Trump, who has promised to deport up to three million people once he takes office, more than Obama deported in two terms. Deportations don’t happen quickly, and the government needs a place to hold people it plans on deporting.

“Because of the high level of detention the ICE is maintaining, they will continue to grant contracts to these exact same prisons that were deemed unfit to detain people under the Bureau of Prisons,” said Bethany Carson, an immigration policy researcher at Grassroots Leadership, a group that advocates against for-profit prisons. “Essentially, I feel it’s a bailout.”

If it’s a bailout, it’s a profitable one.

CoreCivic brought in $474.9 million in revenue last quarter and ICE was the company’s largest single source of revenue. ICE accounts for 28 percent of CoreCivic’s business, according to the company’s 2016 third-quarter filings, up from just 12 percent in 2014. This increase is thanks in large part to a four-year, billion-dollar contract for the 2,400-bed South Texas Family Residential Center.

CoreCivic’s ICE business is picking up, and with Trump’s election, its stock is now soaring. Shares were up 40 percent the day after the election. Since then, they have climbed another 22 percent. Analysts expect the price to keep rising.

“Despite the recent run up … we see more upside,” wrote Ryan Meliker, an analyst at Canaccord Genuity, in a note to clients on private prison stocks.

ICE was detaining 41,000 people a night in November, and officials estimate the daily number of detainees could soon pass 45,000, up from an average of 28,449 in 2015. Private facilities currently hold 73 percent of the ICE detainee population. In comparison, the BOP houses just 12 percent of its prisoners in private prisons.

“Our federal revenue, particularly from Immigration and Customs Enforcement, remained elevated during the third quarter in Arizona and California,” said CoreCivic CFO David Garfinkle during the company’s most recent earnings call. “Further, we have recently seen increased activity from potential customers to utilize our idle facilities.”

The American Civil Liberties Union has estimated that ICE would need more than 100,000 new beds to process the Trump’s promised deportations. During the third quarter of 2016, CoreCivic generated $83.58 a day in revenue from taxpayers for each bed. At that rate, 100,000 new beds would create $3 billion in potential annual revenue for private prisons.

President-elect Trump has also praised the private-prison industry, and his administration could renew BOP contracts with private facilities like CoreCivic. In a June, he told Chris Matthews: “I do think we can do a lot of privatizations and private prisons. It seems to work a lot better.”  

Private prisons might appear more effective to Trump because they insist they deliver cost-savings to taxpayers (and they spend millions on lobbying so state and federal officials feel the same way). But that’s not the case, says Michele Dietch, an expert on private prisons and a senior lecturer at the University of Texas School of Law.

“We’ve had decades of experience now showing that they are not a source of cost savings for government,” Dietch said. “They were built and authorized with that as one of the obvious key objectives, but the cost savings has never really materialized.”

Savings or not, if the government is going to continue to pursue detention as a long term strategy for dealing with illegal immigration, it is going to need more beds. CoreCivic has them. And if a Trump appointee at the Bureau of Prisons decides to reverse course and start using private facilities again, CoreCivic might have to start building more prisons.