The Minnesota Senate approved a measure Monday that raises the bar for when sex offenders and people with mental illness can be released from treatment centers, amid worries that hundreds of potentially dangerous patients may be discharged from programs if lawmakers don't close a legal loophole.

The legislation is in response to a court decision earlier this year allowing the release of Kirk Fugelseth, a 51-year-old man who admitted to abusing 31 children. The court found he no longer needed inpatient treatment and was not a danger before his release last week.

The Minnesota Supreme Court upheld his release earlier this month, making Fugelseth only the second person ever to be fully released in the Minnesota Sex Offender Program's 24-year history.

But lawmakers contend the court didn't distinguish between conditional and full discharges under the program. They said people could re-enter communities before medical and behavioral health experts weigh in.

"It's simply unbelievable that Minnesota's safety has been put in jeopardy by the court's decision," said Sen. Warren Limmer, a Republican from Maple Grove who sponsored the bill fortifying rules on civil commitment releases. "Violent sex offenders and mentally ill people should not be released until we are absolutely sure they are no longer a danger to our community."

The bill clarifies when a person should be released on provisional status or whether they should remain in a treatment facility. The measure easily cleared the Senate, and the House is considering a similar measure.

According to the Minnesota Department of Human Services, 21 sex offenders are on conditional release and under 24-hour monitoring, and 120 people are seeking conditional discharge. More than 230 people classified as "mentally ill and dangerous individuals" are provisionally discharged.

Chuck Johnson, the department's acting commissioner, said those people could petition the court for a full release based on the recent court ruling if the laws aren't changed.

He said it could be "days or weeks" before offenders who are seeking a provisional release could be fully discharged. "Those who are in process are the more immediate concern," he said.

The sex offender program has faced legal challenges for years.

A group of patients last year asked the U.S. Supreme Court to take up their case. They argued the program, which houses more than 700 people in prison-like facilities, violated their rights because it amounted to a life sentence because few people are released.

Limmer said gradual reintegration is in the interest of public safety.

"I would always hope there's a need for redemption ... but this is a unique population," he said, noting that some people respond well to treatment. "But nevertheless, there are many in the system who should not be released."