Kansas just became the 18th state to make it illegal for cops to have sex on the job.

Kansas police officers are now specifically forbidden from having sex with someone during a traffic stop, for example, while they’re interrogating someone in custody, or during an interview in a criminal investigation, according to the bill Kansas Gov. Jeff Colyer signed into law last week.

Rep. Cindy Holscher told the Wichita Eagle that she introduced the bill in response to allegations of sexual abuse in a police investigation into a wrongful murder conviction. Affidavits in the case alleged that, over decades, retired white homicide detective Roger Golubski repeatedly threatened to arrest black women or their family members unless they had sex with him.

Holscher told the Eagle that her decision to introduce the bill was also driven by a case in New York City last September where two NYPD officers allegedly raped an 18-year-old woman in their police van after they arrested her on marijuana charges. The rape kit matched both officers’ DNA, but they claimed the sex was consensual. The case is ongoing, and the judge has so far declined to drop charges against the officers.

In February, BuzzFeed ran a story spotlighting legal loopholes in New York and 34 other states that allow police officers to have sex with people in their custody. While state laws generally prohibit sex between other law enforcement officers like prison guards and inmates, most of those states do not have specific language that addresses sex between police officers and people in their custody. Since the NYPD case, which got nationwide attention, lawmakers in New York, Kansas, Maryland and Georgia, among others, have introduced bills to close the loophole.

Read more: Undercover cops can still sleep with sex workers in Michigan

“While the current laws in Kansas prohibit sexual relations between law enforcement and individuals in jails, etc., the law does not protect persons who are detained, or, say, stopped in their neighborhoods,” Holscher said in written testimony submitted to Kansas’ Juvenile Justice and Corrections Committee. “Of course, most of our police officers work every day to serve and protect our communities. But we do have to protect our citizens from the ‘bad apples’ in the batch.”