America’s generations-old battle over who gets to live in this nation of immigrants is raging anew, and the agency known as ICE has become a lightning rod.

Formally US Immigration and Customs Enforcement, the agency has been described as America’s Gestapo by critics, its own agents are calling to dismantle it, and some citizens and Democrats are rallying behind the hashtag #AbolishIce. At the same time, Donald Trump has hailed ICE as the only thing keeping the country from exploding into “rampant uncontrollable” crime and gang “infestation.”

No matter what side of the US immigration debate you’re on, there’s one thing that everyone can agree on: The current system is a disaster. About 11 million people live in the US without authorization, tens of thousands more try to cross the southern border illegally every month, and thousands of kids are currently in government custody without their parents. Meanwhile, the US’s immigration courts are a bureaucratic backwater, sitting on hundreds of thousands of pending asylum and refugee cases for years.

“There’s no way everyone is going to be happy with what you do,” one former top ICE executive tells Quartz, adding that his agents were expected to “treat people with respect and enforce the law.” Under Trump, however, ICE is being accused of failing even those basic functions. The #AbolishIce movement is just the loudest and latest in a long history of both Democrats and Republicans questioning ICE’s very existence.

What ICE was built to do

“The progressive call to ‘abolish ICE’ is not just a knee-jerk anger at cops,” said Moira Whelan, a former DHS official who also worked on the first Congressional oversight committee for the agency. “It is also a recognition that they aren’t doing what we built them to do.”

“We could not find any documentation that fully explains the rationale and purpose behind ICE’s composition.”

Before the creation of ICE 15 years ago, immigration violations were handled by the Immigration and Naturalization Service, which was part of the Department of Justice, and worked closely with the Department of Labor. A separate force, called Border Patrol, monitored the borders.

In the shell-shocked aftermath of Sept. 11, 2001, then-president George Bush and Congress created the Department of Homeland Security, a mega-bureaucracy that now has 229,000 employees and a $50 billion annual budget. Born from 22 different agencies that reported to different cabinet secretaries, DHS was supposed to streamline the process for getting goods and people into the US, and keep dangerous people out. Its subsidiary agency ICE is supposed to focus on the latter.

ICE’s primary mission is to “prevent acts of terrorism by targeting the people, money, and materials that support terrorist and criminal activities,” as described by the Department of Justice in 2004. The focus was meant to be on crimes like money-laundering and human trafficking, and ways terrorists could get anything from small pox to suitcase bombs into the country.

But did ICE make sense on its own? In 2004, the conservative Heritage Foundation suggested ICE be merged out of existence, by combining it with the new border force, Customs and Border Protection. And in 2005, the Department of Homeland Security’s inspector general concurred in a 175-page report (pg. 19) that there was little reason for ICE to have been created at all:

We could not find any documentation that fully explains the rationale and purpose behind ICE’s composition. One senior official offered the following explanation…ICE was established with not a focus on supporting a particular mission, but on building an institutional foundation large enough to justify a new organization.

Were ICE to just focus on immigration fraud, employee sanctions, and removing dangerous people who were illegally already in the country, it would be a small agency, the report notes. Instead, though, ICE was “sized up,” to become a large bureaucracy in its own right.

How ICE became a deportation machine

In the following years, the agency grew wildly. Its budget jumped in 2009, when Congress started funding ICE detention centers based on arbitrary numbers of beds set by lawmakers. This essentially established a quota of detainees for ICE agents to catch. Most of its budget—$4.1 billion of this fiscal year’s $7.1 billion this fiscal year (pdf, pg. 2)—goes to “detention and removal operations.”

ICE currently maintains over 40,000 beds worth of people who crossed the border illegally, and private contractors are big beneficiaries of these detentions—Geo Group and CoreCivic both made about a quarter of their revenue from ICE contracts in 2017. ICE estimates that the cost to the US taxpayer per bed is about $126 per day, though the Government Accountability office thinks that’s too low.

Today, only the agency’s 6,000 Homeland Security Investigations (HSI) agents are tasked with ICE’s original mission: tracking terrorism and transnational crime syndicates in the US and around the world. About 8,000 ICE agents are dedicated to locating, arresting, detaining, and removing undocumented immigrants; the agency’s 1,100 attorneys and 300 staff also prosecute the government’s immigration cases each year.

As Whelan points out, the focus on immigration violations is a clear sign of drift from ICE’s original mission, when “the transnational crime prospect was the major priority, not moms with three year olds crossing the border, not farm workers or people seeking political asylum.” While ICE isn’t responsible for carrying out Trump’s controversial policy of taking immigrant children from their parents at the border—that’s Customs and Border Patrol—it does hold and deport the parents.

ICE’s 20,000 employees make it one of the smaller parts of DHS, but its $7.1 billion budget is greater than that of the 57,600-employee Transportation Security Administration (TSA), the agency tasked with securing US skies, rails, highways, and mass transit systems.

ICE changes with the president and economic conditions

As the DHS was born, massive changes were happening south of the border. As Mexico’s economy improved, Mexican citizens coming illegally for work plummeted. But people from El Salvador, Guatemala, and Honduras were driven to the US by violence, drought, and, some immigration officials say, lenient US policies.

George Bush Jr. started the “catch and release” policy of releasing these asylum-seekers into the US while they awaited lengthy hearings and trials in the overloaded immigration court system. To stop “catch and release,” Bush said in his 2007 State of the Union address, ICE would add nearly 7,000 more detention beds.

Under Barack Obama, ICE was still responsible for detention and deportation, but its interior functions were redirected. In 2011, John Morton, then director of ICE, ordered agents to exercise “prosecutorial discretion” by focusing on the violators of US immigration laws who posed the greatest threat to national security and border safety. ICE agents struggled with the responsibility. They were told “Make a sound law enforcement decision and we’ll support you,” a former ICE official said, but wondered “If I decide not to arrest someone [who is] here illegally, and they kill someone, then what?”

“It is easier to deal in black and white,” he said.

The Obama administration also started the DACA program, which was meant to provide a path to citizenship for young adults brought to the US illegally as children. This had consequences at the border, ICE and other US immigration officials say. After DACA was announced, “suddenly we had tens of thousands of kids getting thrown across the border,” said Chris Crane, the head of National ICE Council, a union that represents 7,600 ICE officers. Others argue economics contributed to the surge.

By no coincidence, the ICE union and the Border Patrol union were among the few federal government agency unions to endorse Trump ahead of the 2016 election. Crane, a vocal critic of presidential immigration policies for years, said then that “America has been lied to about every aspect of immigration in the United States,” and only Trump can “put politics aside to fix the problem.”

Trump’s nationwide manhunt

Just days after his inauguration, Trump issued an executive order on “Enhancing Public Safety in the Interior of the United States.” A sharp turnaround from the Obama administration’s approach, it instructed government agencies to deport all “removable aliens.”

“Our government has sold out to big business and the Chamber of Commerce.”

The result has been a nationwide manhunt that has ensnared people who have been in the country peacefully for years or decades. Some have children who are American citizens, and many have paid US taxes for years. The people detained or deported include the Salvadoran teenager in Long Island who was an FBI informant, a Long Island man from Albania who’d worked at the same diner for 24 years, a father from Bangladesh who was arrested as he was getting his kids ready for school, immigration activists, and multiple military veterans.

When everyone is a target for deportation, immigration lawyers and some long-time law enforcement officials worry, the agency isn’t focusing resources on what it is supposed to be doing. “The stripping of discretion from ICE officers has been one of the most damaging policies that we’ve seen under this administration,” said Kate Voight, the associate director of government relations with AILA, a group of immigration lawyers that has testified to Congress on immigration issues. It’s a “system-wide escalation at the expense of due process and fairness.”

Under the new system, ICE’s stated commitment to respect has also gone out the window, critics say. When Sokol Vokshi, a 47-year old Long Island waiter whose immigration status has been working its way through the courts for years, reported to a scheduled meeting with ICE officials, he was handcuffed and taken to the airport. ICE wouldn’t let him say goodbye to his teenage daughter, and threw his lawyer out of the room, the attorney recalls.

“They have the discretion to implement the laws in a humanitarian way,” Altin Nanaj, Vokshi’s lawyer, said, “and they’re just acting like robots.” ICE agents may say they’re just doing their jobs, he said, “but so did the Nazis, and they were held accountable.”

ICE acknowledges that the administration influences the way it operates. “As a law enforcement agency, ICE carries out its mission within the framework established by each respective administration,” an ICE spokeswoman said. That framework includes presidential executive actions, and changes with every change of administration, she said. “But ICE’s fundamental mission has been and remains the enforcement of U.S. immigration and customs laws to promote homeland security and public safety,” she said.

What ICE has accomplished under Trump

When he took office, Trump pumped up DHS’s budget, even as he proposed slashing most other agencies’ funding, and said he planned to hire thousands more immigration agents and add more detention beds. In increasingly heated statements, the White House paints immigrants as criminals and animals, although multiple studies and comparisons show they pose less of a threat to US citizens than other US citizens do.

The overall number of people trying to cross the US southern border plummeted in the months after Trump took office. Even so, removals from the interior of the country increased by about 25% (pg 12) for fiscal year 2017, as did removals of African immigrants. ICE also increased overall arrests by over 40 percent, and nearly doubled the number of MS-13 arrests, an ICE spokeswoman told Quartz.

Not everyone at ICE and DHS feels good about the way things are going.

So, while fewer people tried to cross the border in the last fiscal year, the agency is arresting and deporting more people. More than 90% of ICE arrests were related to “public safety and national security threats, illegal reentrants, and fugitives,” the spokeswoman said. said. Morale at ICE, typically among the lowest at federal agencies, rose to its highest level since 2010, she added.

But not everyone at ICE and DHS feels good about the way things are going. Several HSI agents, who deal with ICE’s original mission of terrorism, weapons, and crime syndicates, complain that the agency’s high-profile anti-immigration work has made their jobs impossible. In a letter published by the Texas Observer last week, the agents said that ICE’s reputation has become so toxic that local law enforcement won’t cooperate with them.

State and local law officials “are frustrated, people in ICE are frustrated, and other federal agencies are frustrated because of the obsession with immigration enforcement, and particularly the expansion of efforts targeting non-criminal unauthorized immigrants” said John Cohen, a former acting undersecretary of DHS who has over 30 years experience in law enforcement and homeland security.

Officials also say they are upset about the family separation policy, but point to DHS secretary Kirstjen Nielsen as the cause of the mess. “She owns the decision,” one former DHS official said. The administration is struggling to reunite children with their parents because no one is taking charge, they say.

Even the ICE union registered its disapproval in a letter to the White House.

Even the ICE union registered its disapproval in a February letter to the White House, saying it could no longer support the president on immigration because he was repeating the mistakes of the past. “They’re still playing by the same failed playbook. They can’t change and they can’t innovate.” Crane told Quartz. “They said they would work with boots on the ground people in the field and they didn’t do it,” he said. The union is against the child separation policy, he added.

Ultimately what the US should be doing to fix the country’s massive immigration problem, say Crane, several other immigration officials, and some influential US senators, is to curtail demand. Put more pressure on US businesses not to hire illegal labor, and force employers to use electronic document systems like E-Verify, Crane says. “Our government has sold out to big business and the Chamber of Commerce,” Crane said. “We keep doing it the dirty way, because big business wants that dirty labor,” he said, referring to people working without work visas.

Immigration chaos is politically useful to both sides

The debate over ICE’s existence is in part a proxy for a deeper debate, one that America’s more established immigrants have always grappled with, when faced with newcomers: “Who else gets to be an American?” As the country gears up for midterm elections in November that could determine how history remembers the Trump presidency, the agency’s name has become a rallying cry for both the left and the right.

“We are going to be introducing a wave of change,” Alexandria Ocasio-Cortez, who at 28 is set to become the youngest-ever member of the US Congress, promised a cheering crowd at a billiard hall in the Bronx during a celebration of her surprise election in June. For Ocasio-Cortez and a growing number of Democrats, a key part of that wave is abolishing ICE.

Boston City Council member Ayanna Pressley, who is running for a Massachusetts Congressional seat in November, suggests defunding ICE entirely, and putting anti-terror functions somewhere else. Kirsten Gillibrand, the New York senator, recently joined the call, saying “We need to start over, separating the criminal justice and immigration roles.” And Ron Wyden, the senator from Oregon, told Quartz ” I don’t think ICE is focusing on the right people, and I think a fundamental overhaul is in order here.”

Meanwhile, the White House is attacking senators who criticize the agency on social media, and the Republican Party has inaccurately called it the main defender of US borders (that’s actually Customs and Border Protection). It’s part of the Trump White House’s deliberate strategy to “pour gasoline” on hot-button US issues before November to rally his base to vote—all but guaranteeing, however, that the US’s long-standing immigration problems don’t get fixed any time soon.

Stepping into this mess is Ronald Vitiello, a career border patrol agent who was quietly named ICE’s new director on June 30. His appointment could bring some needed calm, long-time immigration experts across the political spectrum say—but using the agency to inflame voters ahead of the November midterms may be too politically valuable right now for anyone in Washington to let him do it.

Correction (July 8): This article originally stated the INS was part of the Department of Labor; it worked closely with the Department of Labor but was part of the Department of Justice