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 the elderly 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 historically have been disenfranchised.

After fighting back against the accusations for years, Facebook announced it will make significant changes to its platform so that advertisers can no longer target, or exclude based on characteristics like gender or race. This is significant because Facebook’s massive revenue primarily comes from ads, which are so lucrative because of the platform's microtargeting 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 blacks, Hispanics, 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 antidiscrimination 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 that 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. (The Trump administration’s Justice Department 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.”