The House select committee hearings into the Capitol insurrection have established two facts virtually beyond debate: One, former President Donald Trump is culpable for what his followers did that day in support of his unprecedented attempt to overthrow a valid election. And, two, Trump’s scheme was aided by deep flaws in the federal statutes guiding the process of counting and certifying electoral votes.

The second issue, at least, now has a fix in sight. A bipartisan group of senators has unveiled legislation that will make it more difficult for future presidents to engage in the kind of anti-democratic mischief that Trump did, with rational and even-handed changes to current law. In a real sense, members of Congress voting on this will be making a choice between safeguarding democracy or defending Trump’s attempted coup — and risking an encore.

The new legislation overhauls a poorly drafted, 19th-century law governing the certification of elections and makes other changes to repair weaknesses that Trump exploited. It specifies that the vice president’s role in the process is purely ceremonial, so future sitting presidents can’t claim, as Trump did, that their vice presidents have the power to simply set aside the voters’ decision.

The bill would make it more difficult for members of Congress to object to states’ electoral slates, upping the current threshold of one objector each in the House and Senate to one-fifth of members in each chamber. Under the current system, Missouri Sen. Josh Hawley’s announcement in the days before Jan. 6, 2021, that he planned to object to some of the results — the first senator to make such an announcement — was in itself enough to set up the floor debate that helped inspire the rioters. A higher bar for objections could well have averted the whole thing.

The reform package would also require states to appoint their electors as prescribed by their own state laws, without any possibility of changing the rules after Election Day, as Trump and his backers tried to get Republicans in key states to do after the 2020 election.

The measure isn’t a cure-all. It doesn’t, for example, prevent states from changing their laws before Election Day to make it easier for legislatures to bypass the will of the people, which some red states are currently trying to do.

Preventing that kind of undermining of democracy with a federal law would require more federal intrusion into state laws than most congressional Republicans are likely to agree to, and Republican votes are needed in the Senate to pass this. Ultimately, only voters in individual states can stop their leaders from rigging elections in advance.