WICHITA -- Law enforcement officers in Kansas are now banned from having sex with people they stop for traffic violations or detain in criminal investigations under a new state law that many legislators were surprised was necessary. Before Gov. Jeff Colyer signed the law Thursday, Kansas was among 33 states where consensual sex between police and people in their custody wasn't a crime, The Wichita Eagle reported.

Law enforcement officers were banned from having sex with people in jail, but the new law bans sexual relations "during the course of a traffic stop, a custodial interrogation, an interview in connection with an investigation, or while the law enforcement officer has such person detained."

Democratic Rep. Cindy Holscher, of Olathe, introduced the bill. She said the legislation grew from the case of Lamonte McIntyre, who spent 23 years in prison for a double murder he didn't commit.

Get Breaking News Delivered to Your Inbox

McIntyre was released last year after investigators determined the detective who arrested him had long coerced sexual acts from women in Kansas City's black community, including McIntyre's mother, by threatening to arrest them or their relatives. McIntyre's mother said in an affidavit that she believed the detective targeted her son after she spurned his advances.

Holscher said she also was influenced by a New York case where a teenager alleged she was raped by two police officers in the back of their van after she had been handcuffed and told she was under arrest.

The officers have pleaded not guilty to rape and other charges, claiming the sex was consensual and therefore legal. The case highlighted the apparent loophole in the laws in New York and many other states that may allow police to avoid charges or defend themselves against sexual assault accusations by claiming sex acts were consensual.

In the wake of that case, lawmakers in New York in March passed a bill that bans police officers from having sex with people in custody. While New York law had already barred sexual contact between corrections workers and inmates, it didn't previously apply explicitly to police.

"I was shocked," New York Democratic state Sen. Diane Savino said in February when she learned of the oversight. "It should be clear across the state for officers from every department, that when someone is in custody they do not have the ability to consent to sexual activity."

The Kansas bill received bipartisan support. Rep. John Carmichael, a Democrat from Wichita, said also said he was shocked to learn that such behavior wasn't already illegal in Kansas when Holscher first discussed the proposal.

Many officers now wear body cameras, so it would be difficult for law enforcement to get away with sex on the job, said Rep. John Whitmer, a Republican from Wichita.

"Most officers are great guys and women who are working hard, but there's always the one," Whitmer said.