(Reuters) - Facebook Inc has agreed to change its paid advertising platform as part of a wide-ranging settlement to prevent discriminatory and “harmful” practices, the company and U.S. civil rights groups said on Tuesday.

FILE PHOTO: Silhouettes of laptop users are seen next to a screen projection of Facebook logo in this picture illustration taken March 28, 2018. REUTERS/Dado Ruvic/Illustration

Under the agreement, Facebook will create a new advertising portal for ads linked to housing, employment and credit ads that will limit targeting options for those ads across all of its services, including Instagram and Messenger, the rights groups said in a joint statement.

Advertisers on the portal, which will be separate from the system used to advertise other sets of services, will not be able to target ads by age, gender, cultural affinity or zip code, the statement said.

They will also be required to use a minimum geographic radius for location-based targeting to prevent the exclusion of certain communities.

In addition, the company pledged to build a tool allowing users to search all current housing ads listed in the United States, regardless of whether the ads were directed at them.

“There is a long history of discrimination in the areas of housing, employment and credit, and this harmful behavior should not happen through Facebook ads,” Facebook’s Chief Operating Officer Sheryl Sandberg said in a separate statement.

Facebook, the world’s largest social network with 2.7 billion users and nearly $56 billion in annual revenue, has been on the defensive over its advertising practices, while also fending off privacy scandals and disclosures that Russia used its platform to meddle in the 2016 U.S. presidential election.

Complaints over ads-based discrimination have dogged the company since 2016, when news organization ProPublica reported that advertisers could target ads on Facebook based on people’s self-reported jobs, even if the job was “Jew hater.”

ProPublica later reported that it was able to buy discriminatory housing ads and slip them past Facebook’s review process, despite the company’s claims it was blocking such ads.

Since then, Facebook has faced sustained legal pressure over the issue from the National Fair Housing Alliance, the American Civil Liberties Union and the Communications Workers of America, among other groups and individuals.

In five separate lawsuits, the groups alleged the company’s audience selection tools enabled advertisers to exclude specific demographics from seeing job postings and other opportunities.

Facebook’s settings “allowed advertisers to create ads that excluded people of color or families with children,” said Sandra Tamez, head of the Fair Housing Council of Greater San Antonio, which was part of Tuesday’s settlement.

Under U.S. law, including the federal Fair Housing Act, it is illegal to publish certain types of ads if they indicate a preference based on race, religion, sex or other specified classifications.

Facebook last year reached a similar settlement with Washington state to end discriminatory ad targeting. It said at the time that it had already removed thousands of categories of potentially sensitive personal attributes from its exclusion ad targeting tools.

Wit the new settlement, Facebook has committed to creating its ads portal by Sept. 30 and to implementing other changes by the end of the year.