MINNEAPOLIS (AP) — A federal judge has ruled that Minnesota's sex offender treatment program is unconstitutional, but has deferred any immediate action to await further proceedings on a remedy.

U.S. District Judge Donovan Frank largely sided with the more than 700 residents who were civilly committed to the Minnesota Sex Offender Program after they completed their prison sentences.

Their lawyers argued during a nearly six-week bench trial in February and March that the program is unconstitutional because nobody has ever been fully discharged from it, even those thought to be at low risk of committing new crimes.

The state says it has improved the program, including moving more patients through treatment and perhaps toward provisional release.

Frank found the secure, civil confinement program unconstitutional. He is convening state leaders for an August remedies phase but says he is prepared to act if they don't.

Throughout his 76-page ruling, Frank says elected officials have been reluctant to modify the indefinite confinement of more than 700 sex offenders out of political fear. But Frank says "politics or political pressures cannot trump the fundamental rights" of those in the program.

He stressed that the U.S. Constitution "protects individual rights even when they are unpopular."

In his ruling, the judge lays out more than a dozen conditions for a restructured program, including that less-restrictive alternatives be implemented and new evaluation and discharge procedures be developed.

Gov. Mark Dayton says there won't be immediate changes to the Minnesota Sex Offender Program in response to the ruling. The Democratic governor says he'll work with the state attorney general to continue to defend the program. It wasn't clear if that means an appeal to a higher court or some other course of action.

The lead attorney who successfully challenged the constitutionality of the program says fixing it will require a combination of legislation and executive action. Dan Gustafson said at a news conference Wednesday the Department of Human Services, which runs the program, can make some changes by itself. But he says some will require more money that will have to come from the Legislature if the department can't reallocate enough money within its own budget.

And he says there are some things in the state's civil commitment law —like the lack of a judicial bypass that would let program residents go directly to court to seek release — that only the Legislature can change.

If that requires a special session at some point, Gustafson says they'll ask for that.