Mark Zuckerberg, chief executive officer and founder of Facebook Inc., speaks during a joint hearing of the Senate Judiciary and Commerce Committees in Washington, D.C., U.S., on Tuesday, April 10, 2018.

Facebook settled five lawsuits alleging that its advertising systems enabled discrimination in housing, credit and employment ads. For the social network, that's one major legal problem down, several to go, including government investigations in the U.S. and Europe over its data and privacy practices.

As part of that settlement, Facebook says it will overhaul ad targeting for housing, credit and employment ads so they can't be used to discriminate on the basis of race and ethnicity, gender and other legally protected categories in the U.S., including national origin and sexual orientation. The social media company is also paying about $5 million to cover legal fees and other costs.

Facebook and the plaintiffs — a group including the American Civil Liberties Union, the National Fair Housing Alliance and others —called the settlement "historic." It took 18 months to hammer out. The company still faces an administrative complaint filed by U.S. Department of Housing and Urban Development in August over the housing ads issue.

What's not yet clear is how well the safeguards will work. Facebook has been working to address a slew of social consequences related to its platform, with varying degrees of success. Last week, it scrambled to remove graphic video filmed by a gunman in the New Zealand mosque shootings, but the footage remained available for hours on its site and elsewhere on social media.

Earlier in March, CEO Mark Zuckerberg announced a new "privacy-focused vision" for the company to focus on messaging instead of more public sharing — but he stayed mum on overhauling Facebook's privacy practices in its core business.

Galen Sherwin, senior staff attorney at the ACLU and the group's lead attorney on its suit, praised the settlement as "sweeping" and said she expects it to have ripple effects through the tech industry.

Facebook agreed to let the groups test its ad systems to ensure they don't enable discrimination. The company also agreed to meet with the groups every six months for the next three years, and is building a tool to let anyone search housing-related ads in the U.S. targeted to different areas across the country.

Discrimination hasn't Facebook's only problem with ad targeting. In the past, it's taken fire for allowing advertisers to target groups of people identified as "Jew-haters" and Nazi sympathizers. It's also still dealing with fallout from the 2016 election, when, among other things, Facebook allowed fake Russian accounts to buy ads targeting U.S. users to stir up political divisions.

One of the complaints said that Facebook violated the Fair Housing Act because its targeting systems allow advertisers to exclude certain audiences, such as families with young children or disabled people, from seeing housing ads. Others alleged job discrimination, with ads being shown to men but not women in traditionally male-dominated fields, or only to younger users.

As part of the changes, advertisers who want to run housing, employment or credit ads will no longer be allowed to target people by age, gender or zip code. Facebook will also limit the targeting categories available for such ads. For example, such advertisers wouldn't be able to exclude groups such as "soccer moms" or people who joined a group on black hair care.

Endlessly customizable ad targeting is Facebook's bread and butter. The ads users see can be tailored down to the most granular details — not just where people live and what websites they visited recently, but whether they've gotten engaged in the past six months or share characteristics with people who have recently bought a BMW, even if they have never expressed interest in doing so themselves. It's how they company made $56 billion in revenue last year.

Sheryl Sandberg, Facebook's chief operating officer, would not say whether the changes will hurt the company's advertising revenue. The most important thing, she said, was to protect Facebook's users from discrimination.

"Today's changes mark an important step in our broader effort to prevent discrimination and promote fairness and inclusion on Facebook," she said in a blog post Tuesday . "But our work is far from over."