Should our efforts to bring in highly skilled immigrants rely on a random visa lottery and help companies deliberately replace native tech workers with cheaper foreign labor? That is an honest-to-God question raised by Donald Trump’s new “Buy American and Hire American” executive order, which calls out the bizarre feature of our immigration policy known as the H-1B visa.

Let me start this diatribe by stipulating there are numerous benefits to high-skill immigration in general, especially relative to the low-skill immigration we’ve disproportionately seen in recent decades. As I spelled out in February using data from the census and elsewhere, better-educated immigrants earn more money, are more likely to speak English, are less likely to have children out of wedlock, and are more likely to share important American values such as a belief in free speech. But the H-1B program does far less than it could to harness these benefits and harms middle-class American workers in the process.

The H-1B is a “nonimmigrant” visa given for a three-year period; it can be extended for another three years, and employers can sponsor H-1B holders for green cards as well. Each year, 65,000 new H-1Bs are given to workers in “specialty” jobs (primarily in technology) that require at least a bachelor’s degree, and another 20,000 go to those in jobs requiring a master’s or better. Those hired by universities are exempt from the caps—a seemingly small provision of the law that roughly doubles the total number of H-1Bs awarded—and there is an exception to the degree requirement for fashion models.

An employer sponsoring an H-1B applicant must, as the Department of Labor’s website puts it, attest that the worker’s pay will be “at least equal to the actual wage paid by the employer to other workers with similar experience and qualifications for the job in question, or the prevailing wage for the occupation in the area of intended employment—whichever is greater.” Some employers also must attest that they tried to recruit Americans to fill jobs that pay less than $60,000.

That sounds like what Donald Trump has said he wants: a “merit-based” immigration system that puts the needs of Americans first. But all is not as it seems.

For one thing, the “prevailing wage” requirement is a loophole-ridden farce, with one analysis suggesting that the typical H-1B worker is actually cheaper than a comparable native by $14,000 to $26,000 per year, depending on the city. Moreover it is simply not the case that America is facing a shortage of tech workers and that employers must resort to foreign hires even for jobs that pay well. Instead, many employers use the program to bring in lower-paid workers from abroad to directly replace native workers, in particular swapping older and more experienced natives for younger foreigners. Even better for employers, the foreign replacements are indentured, as it’s the employer, not the worker, who actually holds the visa. A worker who loses his job has to go home.

There are entire firms that specialize in importing foreign tech workers and hiring them out to do work for American companies. Indeed, they are some of the biggest H-1B sponsors, as the Boston Globe documented in 2013:

Twenty percent of the 134,780 H-1B petitions approved last year went to just four firms: Cognizant Technology Solutions, Tata Consultancy Services, Infosys, and Wipro. The latter three are among India’s biggest outsourcing giants. Cognizant, headquartered in New Jersey, grew out of a partnership between Dun & Bradstreet and an Indian firm.

Iconic US companies, including Walmart and 7-Eleven, hire these firms to do IT work. The outsourcers can do it inexpensively, not only because they ship some of the work to India, but also because they bring temporary workers to the United States. Sometimes temporary workers come, learn the job, and take the work back to India for good. Other times, the job stays here but is filled by a rotating cadre of H-1Bs. When Molina Healthcare fired its IT staff, it didn’t apply for H-1B workers to replace them. It got them through Cognizant, the largest consumer of H-1B visas last year.

Indeed, outsourcers have hijacked the H-1B program. Consider that Facebook, the epitome of a tech company that can seek out the world’s best talent, was approved for just 307 H-1B workers. ExxonMobil got 58. The vast majority of participating companies got just one or two. Yet Cognizant got 9,281 of the visas. Tata got 7,454.

Such firms’ practices have been a generous fount of horrifying anecdotes and even lawsuits. In the prototypical case, an employer lays off its tech staffers, replaces them with workers from an outsourcing firm—and instructs the old employees to train their replacements before they go if they want their severance pay.

Laid-off Disney employees have sued the company alleging it colluded with Cognizant and HCL to sub out native workers for H-1Bs. The Molina incident spawned lawsuits as well, as did a similar situation at the Screen Actors Guild. And in 2013 Infosys paid $34 million to settle a lawsuit with the federal government over its immigration practices. All it admitted was violating record-keeping requirements, but according to the government Infosys had knowingly brought in foreign workers on B-1 visas (intended for short business trips, even more limited than an H-1B) to do jobs that native workers would otherwise take, and taught them how to deceive U.S. authorities about the work they would be doing.

This state of affairs is especially curious considering that nowadays applications for H-1B visas exceed the number available several times over. One might think the federal government, faced with this situation, would find a rational way to dole them out, one that weeded out employers searching for cheap labor rather than top talent. Maybe the government would auction the visas off to employers or at least give them to the workers who were going to be paid the most, maximizing tax revenue and directing immigrant competition at the richest possible native workers.

But no, the visas are passed out through a random lottery, with the one wrinkle that the highest-educated applicants get two chances to win (once for the 20,000 advanced-degree slots and then again for the 65,000 BA slots).

So what is Trump doing to address this? Not much yet, aside from vowing a crackdown on fraud in the program. But his new order instructs various executive departments to “suggest reforms to help ensure that H-1B visas are awarded to the most-skilled or highest-paid petition beneficiaries.”

Some tweaks may be possible through administrative action. At a briefing last week, a Trump-administration official mentioned increasing fees or adjusting the program’s wage scale.

But deep reforms will require action from Congress. For example, while the use of a lottery is not spelled out in federal law, the law doesn’t give the executive branch much room to exercise good judgment, either. What it technically says is that visas should be granted in the order in which the petitions were received; the lottery is a regulatory response to the fact that an excess of applications flood in immediately on the first day they’re accepted each year. (A lawsuit demanding the use of a waiting list instead of a lottery was thrown out of court last month and has been appealed.)

One proposal from Rep. Darrell Issa (R.-Calif.) would raise the wage at which employers are exempt from the requirement to recruit Americans first (or at least “attest” they tried to) from $60,000 to $100,000. Another, more aggressive bill, from Rep. Zoe Lofgren (D-Calif.), would scrap the lottery and give the visas to the highest-paying companies. The latter jibes with a suggestion floated by Trump advisor Stephen Miller earlier this year.

If one problem with American immigration policy is that it is too focused on low-skilled immigrants, another is that a major part of it dealing with high-skill immigration is broken. Our current H-1B system forces employers to play a game in which they pretend they’re paying foreign workers the “prevailing wage,” and then ultimately comes down to literally handing visas out at random—a process exploited by companies that specialize in the intentional displacement of native tech workers. It is an odd way for the most powerful country in the world to make such important decisions.

Robert VerBruggen is managing editor of The American Conservative.