Almost everyone wins when it comes to referral hiring, through which an employee recommends someone for an opening at his or her company. The job applicant comes in the door with a personal recommendation and is therefore more likely to get the job. Companies cut hiring costs since referral hires take less time, start the job quicker, and stay at companies longer. The referral hires themselves report higher levels of satisfaction. And the original employee who did the referring often gets a nice cash bonus and a new work friend.

It’s a nice, closed-loop system that works out well for everyone—that is, unless you don’t have the right network to get the job. Referral hiring isn’t great for diversity.

“Referral networks can lead to lesser diversity or—to put it another way—exacerbate between-group inequality,” said Ian Schmutte, an economics professor at the University of Georgia. “It’s very clear that people who get referrals tend to get referrals of the same race, gender, ethnic group, or national origin.” Schmutte’s research has found that people tend to look to their social circles for referral hiring. Those groups are often made up of similar people, a phenomenon known as homophily.

Using a data set from Boston that matches individuals to both their home and work locations, Schmutte found that a pair of workers living in the same block are three times more likely to work at the same company than a pair of workers living in the same neighborhood. These effects are stronger for workers of the same race and the same gender.

It’s not just a matter of valuing diversity for its own sake. Companies with more diverse workforces tend to perform better. A McKinsey report from 2015 found that among 366 companies, those with gender diversity outperform those without it by 15 percent; those with ethnic diversity outperform those without it by 35 percent. For every 10 percent increase in racial and ethnic diversity on the senior executive team at a U.S. company, earnings before interest and taxes rise 0.8 percent, the report found. As a result of findings like these, organizations spend millions of dollars on inclusion programs, which largely don’t work.

For all the talk of diversity, companies love referral programs, which are, perhaps unwittingly, hurting their chances of diversifying workplaces. John Sullivan, a professor of management at San Francisco State University and an expert in human-resources strategy, has called referrals a “powerful” way to build a competitive workforce. It’s cheap and leads to better hires. What better way to market a company than through an enthusiastic review of a current employee?

But many of the companies that rely most on employee referrals for hiring also have alleged commitments to diversity that they fail to meet. Palantir got in trouble with the federal Labor Department for relying too heavily on referral hiring, which has led to a homogenization of its workforce. Google, Facebook, and Twitter all landed on a recent Glassdoor list of the top 30 companies that use referrals for hiring and have had a hard time hiring non-white and non-Asian male workers. Google, for example, pledged just under $1 million to a nonprofit group that teaches technical skills to black and Latino college students. Facebook, in an attempt to move its numbers, altered the recruiting process to incentivize hiring for diversity; recruiters would get more points for diversity hires, which lead to better performances reviews, bonuses, and raises.

These efforts haven’t worked. Only 4 percent of Facebook’s U.S. employees are Hispanic and 2 percent are black, as of summer 2016—and those numbers haven’t moved in two years. Google’s staff is now 69 percent male, down from 70 percent male a year ago, according to its own diversity report.

Even if standard referral programs risk reinforcing workplace demographics, there might be a way to turn employee recommendations into engines of diversity. Accenture and Intel, which also have predominantly male and white workforces, started dangling bigger bonuses for diversity hires made through referral programs. Pinterest saw a large increase in diverse candidates when it ran a similar program over a six week period last year.

Getting rid of referrals altogether isn’t the answer. “Social interactions provide information that is useful to firms that are trying to screen workers for jobs where the skill set is not that obvious or easy. You want to know: Is somebody going to show up to work? Are they going to be a good worker?” Schmutte said. “But because they operate along lines of race or ethnicity, they might still block people off from certain types of jobs.”