It appears that Senate Republicans managed to make a $289 billion or so mistake while furiously hand-scribbling edits onto the tax bill they passed in the wee hours of Saturday morning. The problem involves the corporate alternative minimum tax, which the GOP initially planned to repeal, but tossed back into their stew at the last second in order to raise some desperately needed revenue. The AMT is basically a parallel tax code meant to prevent companies from zeroing out their IRS bills. It doesn’t allow businesses to take as many tax breaks but, in theory, is also supposed to have a lower rate.

Except not under the Senate bill. When Mitch McConnell & co. revived the AMT, they absentmindedly left it at its current rate of 20 percent, the same as the new, lower rate of the corporate income tax that the bill included. As a result, many companies won’t be able to use tax breaks that were supposed to be preserved in the legislation, including the extremely popular credit for research and development costs. Corporate accountants started freaking out about this over the weekend, but the situation reached high farce when a group of lawyers from Davis Polk pointed out that, by leaving the AMT intact, Republicans had essentially undermined their bill’s most important changes to the international tax code.

Without getting too stuck in the weeds, the GOP’s bill was supposed to take the U.S. from a “worldwide” system of taxation, where the IRS tries to take a cut of profits American companies earn anywhere on the globe, to a modified “territorial” system, where companies could bring back their profits either tax-free or at a much lower rate. With the AMT still kicking around at 20 percent, though, “the United States would continue to operate under a worldwide system of taxation,” the lawyers wrote.

Keeping the AMT was supposed to raise $40 billion, but that already appears to be a gross underestimate. (The figure came from Congress’ Joint Committee on Taxation, whose analysts I can only assume were running on Red Bull and fumes while trying to provide the GOP with last-minute scores.) NYU Law professor and tax expert Lily Batchelder concludes that the AMT will actually cost companies at least $329 billion—good for limiting the blow to the deficit, bad for the corporations who are supposed to be stumping for this legislative Frankenstein—just based on the value of the R&D credits and international exemptions that have been rendered useless.

Appears corporate AMT provision probably raises >$300B, not $40B JCT estimated under duress Fri night. This means Rs have to take Senate bill to conference and can’t just have House pass it, unless they want to *really* piss off bus community. 1/5 — Lily Batchelder (@lilybatch) December 6, 2017

I’m getting >$300B from fact that provision appears to repeal R&D credit, which costs ~$113B, and participation exemption, which costs $216B. See JCT estimates at https://t.co/odhMFYTc68 and https://t.co/dcffBY0NKb. 2/5 — Lily Batchelder (@lilybatch) December 6, 2017

And corporate AMT provision does a lot more than this, so even $300B is probably low-balling. 3/5 — Lily Batchelder (@lilybatch) December 6, 2017

When I talked to Batchelder briefly on the phone Tuesday night, she pointed out that while the GOP’s AMT debacle would end up raising more money than expected, there are almost certainly other, undiscovered mistakes in the bill that would lose revenue. “I think this evidences what can go wrong when you try to pass massive tax reform this quickly,” she said.

On the bright side, this mammoth screw-up will make it harder for the House to simply pass the Senate’s bill if the GOP’s conference committee hits a wall. Republicans have to enact something that fixes this, lest they tick off the very donors this legislation was meant to appease.