U.S. District Judge David Alan Ezra struck down a Texas law on Wednesday that would have required hospitals and clinics to bury cremate fetal remains, causing another courtroom setback for state leaders and anti-abortion groups.

Under Senate Bill 8, passed in 2017, healthcare facilities including hospitals and abortion clinics would be required to bury or cremate any fetal remains — whether from abortion, miscarriage, stillbirth, or treatments for ectopic pregnancy regardless of patients’ personal wishes or beliefs. Legislators passed the bill following a ruling that year by U.S. District Judge Sam Sparks that struck down a similar rule implemented by the Texas Department of State Health Services. At the time Sparks said it was vague, caused undue burden on women and had high potential for irreparable harm.

“I will tell you that in this regard and it was not even a close call, showed that the legal issues aside the implementation of this law as I have pointed out would cause and if allowed to go into effect, would be a violation of a woman’s right to obtain a legal abortion under the law as it stands today,” Ezra said Wednesday.

Ezra issued a temporary injunction on SB 8 in January after the Center for Reproductive Rights and Whole Woman’s Health sued Texas, blocking the law from going into effect on Feb. 1.

The ruling comes after a five-day trial in July at which a slew of patients, health providers, state agency officials, bioethicists, cemetery directors and religious leaders got on the witness stand.

Abortion opponents have argued that the law is a means to bring human dignity to fetuses. But reproductive rights advocates said it was another way for Texas to punish women who choose to have an abortion, and that the cost of the burials would be passed on to patients, making abortions harder to obtain for low-income Texans. But during the trial, state attorneys dropped their argument that SB 8 protects the health or safety of patients and plaintiffs’ attorneys cast aside their arguments about costs to patients and providers.

Multiple doctors and health advocates who testified said women often don’t ask what happens to their fetal tissue, since they assume it’ll be treated like medical waste. Providers also said they have experienced challenges trying to find medical waste vendorswilling to work with their clinics. A top reason, they said, is that vendors are unwilling to endure backlash and harassment from anti-abortion advocates.

Meanwhile, state attorneys said the rule was designed to provide fetuses a better resting place than a landfill. They argued that women would not be harmed by the law and that there were churches and cemeteries statewide willing to help medical providers dispose of fetal remains.

Ezra’s decision comes ahead of U.S. Senate confirmation hearings beginning Sept. 4 for President Donald Trump’s Supreme Court nominee Brett Kavanaugh. If confirmed, Kavanaugh would replace Justice Anthony Kennedy, who announced his retirement in July. The prospect of Trump appointing a second Supreme Court justice has fueled speculation about the future of abortion policy, including the potential overturning of Roe v. Wade.