Legislators shouldn’t and generally don’t claim to be perfect. Too many well-intentioned laws have had to be tweaked a bit after their passage.

So the next time Alabama legislators gather in Montgomery — whether it’s in January for the 2018 regular session, or for a special session before then — they need to be tweaking the state’s 2010 law that forbids school employees from having sex with students under the age of 19.

A Morgan County judge last week declared that law unconstitutional and tossed out two cases brought under it against a female teacher from Decatur and a male teacher from Falkville. The woman was accused of having sex with two male students, ages 17 and 18 at the time. The man was accused of having sex with a 17-year-old female student.

The law makes that a Class B felony, and anyone convicted under it faces up to 20 years in prison and must register as a sex offender.

There have been other, unsuccessful challenges, but Circuit Judge Glenn Thompson was the first to side with defendants. He said the law is overly broad and makes it impossible to determine if parties in such cases are consenting adults (Alabama’s age of consent is 16), whether any consent was “illegitimate or coerced” or whether school employees or teachers actually are in specific positions of authority over students.

Prosecutors have vowed to appeal Thompson’s decision — because it’s a constitutional issue, the attorney general’s office will be involved — and it’s likely the case will wind up at the Alabama Supreme Court. We think it’s just as likely that the court will punt this back to the Legislature to fix — and again, that needs to be a priority.

The fix won’t be difficult. A revised law simply needs to acknowledge the disparity in power between teachers and other school employees and students, and restate that even for older students, schools continue to operate in loco parentis — in the place of a parent. We think that renders any question of consent moot.

A teacher on hall monitor or early morning duty certainly can discipline a student who’s not in one of his or her classes. The line of authority between teachers and students doesn’t have to be specifically drawn out on a flow chart; it’s inherent.

The same is true with school employees. We hate to deflate students’ egos, but office personnel, janitors and lunchroom workers outrank you.

Opponents of the law say in its current form, it could criminalize consensual relationships between teachers or employees at one school, and students at another school. It might be difficult to establish an inherent line of authority there, but we’re loath to rely on the good sense of the supposed adults in such situations.

Face it, there’s an “ick” factor here that can’t be avoided. What parent sends a teenager to school thinking he or she might get close enough to a teacher where mutually raging hormones will cause problems? What teacher would even allow that to happen? (We can recommend some online dating sites for folks that desperate for companionship.)

Alabama has had more than its share of these cases in recent years (there have been some locally), and in 2015 was proclaimed the nation’s per capita leader in teacher-student sexual encounters.

Given that, one could say the law hasn’t been effective. That doesn’t negate the need for it. Make it right, make it work.