On Tuesday, Facebook reached a historic settlement with civil rights groups that had accused the company of allowing advertisers to unlawfully discriminate against minorities, women, and older people by using the platform’s ad-targeting technology to exclude them from seeing ads for housing, jobs, and credit—three areas with legal protections for groups that have historically been disenfranchised.

After fighting back against the accusations for years, Facebook announced it will make significant changes to its advertising platform so that advertisers can no longer target, or exclude, based on characteristics like gender or race. This is a big deal because Facebook’s immense revenue primarily comes from ads, which are so successful because of their micro-targeting capabilities. But when a company or advertiser shows an ad only to certain people—say, people under the age of 55, as Facebook allegedly did when it placed ads on its own site for jobs at Facebook—that excludes a protected class of workers. And that’s illegal under federal law.

“It is a game-changer,” says Lisa Rice, the executive vice president of the National Fair Housing Alliance, whose lawsuit against Facebook was among those settled Tuesday. “The settlement positions Facebook to be a pacesetter and a leader on civil rights issues in the tech field.”

The settlement resolves five separate cases that had been brought against Facebook over discriminatory advertising since 2016, following a ProPublica investigation that revealed Facebook let advertisers choose to hide their ads from black, Hispanic, or people of other “ethnic affinities.” Lawsuits soon followed. The most recent case was an EEOC complaint by the American Civil Liberties Union in September, alleging that Facebook allowed job ads to discriminate against women.

As part of the agreement, Facebook will build a designated portal for advertisers to create housing, employment, and credit ads, which will not allow targeting users by age, gender, zip code, or other categories covered by anti-discrimination laws. Microtargeting options that appear to relate to these protected categories will be off-limits, as well, and Facebook’s lookalike audiences tool will also incorporate these restrictions. Any advertiser who wants to run an ad on Facebook will be required to indicate if their ad is related to one of these three things.

Additionally, Facebook will build a tool for anyone to view any housing ad anywhere in the US, regardless of who is targeted for or where you live. According to the Washington Post, Facebook has said it will make these changes by the end of the year.

“Housing, employment and credit ads are crucial to helping people buy new homes, start great careers, and gain access to credit. They should never be used to exclude or harm people,” Facebook COO Sheryl Sandberg wrote in a post announcing the settlement. “Getting this right is deeply important to me and all of us at Facebook because inclusivity is a core value for our company.”

But Facebook has not always led from the front on this issue. Initially, the company sought to dismiss the cases brought against it by the civil rights groups, arguing, among other things, that it was immune from charges of facilitating discrimination under the Communications Decency Act of 1996. (Trump’s Department of Justice disagreed, filing statements of interest in two of the cases against Facebook: Onuoha v. Facebook, and NFHA v. Facebook.)

“We were in these settlement talks for two years,” says Peter Romer-Friedman, a lawyer at Outten and Golden, which represented plaintiffs in multiple cases against Facebook. “The fact that more and more evidence was proffered and viewed by the public and new cases came forward and identified how users could be discriminated against helped all the parties understand how serious the problem was.”

Think of a category people might fall into, and Facebook can likely divide users up according to it. The company tracks people not only on its main platform, but also on Instagram and Messenger, both of which it owns, and across the web and smartphone apps. That’s how its whole ad model works: by tracking user behavior and characteristics and letting advertisers microtarget products—from clothes and furniture to houses and jobs—to the kinds of people they most want to reach.

That’s also why Facebook’s advertising platform is so valuable: in 2017, according to its annual earnings report, the company made $39.94 billion on ads alone. Its total revenue that year was $40.65 billion, meaning ads accounted for roughly 98 percent of revenue.

That tracking—and the entire ad model it enables—has been under attack lately, not just for its discriminatory capabilities, but also its general privacy invasion. In Germany, the state’s antitrust regulator ruled in February that those data tracking practices were illegal, because Facebook is the dominant social media company in the country and was forcing users to agree to invasive data gathering in order to participate.

“Facebook will no longer be allowed to force its users to agree to the practically unrestricted collection and assigning of non-Facebook data to their Facebook user accounts,” Andreas Mundt, the head of Germany’s antitrust regulator, said. Facebook vowed to appeal at the time of the ruling; the company did not provide any information on the status of an appeal by press time.

Facebook is also facing investigations from the Federal Trade Commission, the Securities and Exchange Commission, and prosecutors in multiple states for its privacy and data practices.

In response to all of this pressure, CEO Mark Zuckerberg recently announced a “pivot to privacy” that would result in a whole new platform—the business model of which is yet to be determined. As for Tuesday’s announcement, it’s not totally clear how much this settlement will impact the company’s bottom line. A spokesperson for Facebook would not tell WIRED what percentage of total ads on the platform are for housing, employment, or credit. But civil rights leaders involved in the settlement say it’s clearly a lot. “Like everything in life, everything is now on Facebook and there have been huge upticks [in the amount of ads] on Facebook and other social media for employment, housing, and credit,” says Romer-Friedman.

On the new housing, employment, and credit ad portal, advertisers will only see a few hundred options for targeting—as opposed to the tens of thousands they’ll still see on the regular ad platform. But even on the special ad flow, advertisers could easily get around Facebook’s new anti-discrimination precautions. The new design won’t preclude people from uploading their own curated list of people to target ads to—a list that could be totally discriminatory but still compliant with the new service. “The settlement doesn’t address audiences that are created by an advertiser with their own list,” notes Romer-Friedman, adding that employers, housing providers, and banks “really ought to be looking at their list to make sure they are not excluding people.” In other words, employers will need to promise to do the right thing. Facebook already requires advertisers to certify that they are in compliance with the law.

Despite those drawbacks, civil rights advocates are applauding. And they are confident Facebook will follow through. The company has agreed to twice-annual meetings with the groups, as well as ongoing trainings with outside experts on these issues. Facebook has agreed to let the NFHA, the ACLU, and others conduct independent testing of its ad sites to make sure Facebook does what it says it will.

“If any advertiser was trying to skirt or circumvent the system, we have methods for ferreting that out and we’ll be able to bring that to the attention of Facebook,” says Rice.

In her post, Sandberg thanked the civil rights groups for helping the company “promote fairness” on the site. As with most positive change from Facebook, today’s settlement is reactive, and late. But it’s on target.