One of the most convoluted plotlines of the Eighty-sixth Legislature may be, God willing, finally reaching its end. And, hey, it’s a happy, if wacky, ending! Last night, when normal people had retired for the day, the House passed an important piece of criminal justice reform that limits police officers’ ability to arrest people for minor offenses. If you’ve been following along, this was now the seventh time the thing had come up for a vote; the legislation had more lives than a Buddhist cat.

Advocates say that limiting arrests for Class C misdemeanors, like the one Sandra Bland was subjected to, could prevent tens of thousands of unnecessary arrests a year at no cost to public safety. But the bipartisan reform effort has been fiercely opposed by law enforcement groups, particularly the powerful Combined Law Enforcement Associations of Texas.

At first, that didn’t seem to be a problem. Earlier this month, a bill prohibiting Class C arrests sailed through the House 126 to 20; it included CLEAT-approved compromise language preserving the ability of officers to make arrests in some circumstances. But after the bill was finally passed, things went haywire. Democrats decided the language they had previously approved had been too broad. So the bill’s Republican author, state representative James White, made an extraordinary motion to essentially have a do-over vote in order to narrow the language. Instead, Democrats killed the entire bill outright, 55 to 88. A motion to reconsider that vote failed by just two votes on the following Friday, partly because so many Democrats had left early for the weekend.

In the third act of this tedious play, state representative Joe Moody, a savvy Democrat from El Paso, made a last-ditch effort on Monday to revive the reform by tacking the measure onto an unrelated criminal justice bill he was carrying. Moody’s provision  was more modest than White’s proposal: It didn’t prohibit police officers from making arrests for Class C misdemeanors but instead instructed courts to dismiss charges if the arresting officer couldn’t provide a compelling reason as to why the person had been arrested.

Moody’s amendment was easily added to his bill on the floor, and nobody spoke against it at the time. But overnight, CLEAT and other opponents got to work. When it came time to vote on the bill again Tuesday, for final passage, they were ready. State representatives Phil King and Mike Lang, both Republicans in the Blue Lives Matter mold, stood to speak against it, arguing that it would result in criminals going free.

Moody reminded the chamber of the recent 126–20 vote. When the vote came in, it was a tie: 71 to 71. The bill failed. This time, it was Republicans who had killed the bill—no Democrats voted against it, and only a handful of more Libertarian-minded Rs voted for it.

But Moody refused to give up, and throughout the day negotiated with Republicans to reword the bill in a manner that would produce a few more yes votes. He eventually produced new language. In order to justify an arrest, police would have to articulate reasons why the person posed an ongoing threat to public safety or order, why the person could not be identified, or note that the person had refused to sign a citation.

Because the language does not prohibit officers from making arrests, only changes what happens after, it likely won’t be as effective at reducing arrests as White’s bill would have been. And it is unclear what will happen when the bill returns to the Senate, which has been coolly skeptical about measures like these. Next session, advocates will try to build on it.

But it’s still a significant achievement. After all, it took seven tries to get it passed—more than one advocate called it the wildest thing they’d ever seen happen at the Legislature. It was widely loved by both parties the first two times, then killed by Democrats, then killed a second time by apathy, then widely supported again, then killed a third time by Republicans and resuscitated, finally, by a narrow bipartisan vote. Democracy in action, I guess.