The State of Michigan has agreed to spend $87 million in a proposed settlement to replace thousands of lead pipes throughout Flint over the next three years, the latest effort by state and city officials to fix the contaminated water system.

The state may use a combination of federal and state funds for the project, which, if approved, would settle a lawsuit brought last year by a coalition of Flint residents and national groups. The suit blamed city and state officials for failing to protect residents from drinking lead-tainted water for more than a year.

A federal judge is expected to review the agreement during a hearing in Detroit on Tuesday. The proposed deal also calls for the state to provide free bottled water and to conduct extensive testing of Flint’s tap water for lead in the coming months. By January 2020, the agreement says, the city will have replaced pipes in and around thousands of homes — perhaps 18,000 of them — speeding up a project that began last year to replace corroded lead pipes. Pipes made of lead or galvanized steel are expected to be replaced with copper.

“This proposed agreement is a win for the people of Flint,” said Dimple Chaudhary, a lawyer for the National Resources Defense Council. “It provides a comprehensive framework to address lead contamination in Flint’s tap water. The agreement is a significant step forward for the Flint community, covering a number of critical issues related to water safety.”