Things get pretty wild in the Senate during Season 2 of “House Of Cards,” which came out Friday on Netflix. If you haven’t watched though the end of the third episode of the new season, consider this a fair warning that there are MAJOR SPOILERS below.

If you have seen it and are wondering how Frank Underwood — the calculating, murderous, newly minted vice president — masterminded it, and whether his bizarre maneuvering is legal (short version: it is), read on.

The back story is that Underwood wants to get an omnibus spending bill through the Republican-controlled Senate. The big compromise amendment pushed by the Democratic White House to avert a shutdown and secure a bipartisan victory is an increase in the retirement age to 68, phased in over five years. The Republican majority leader, Hector Mendoza, is on board. But Mendoza is facing a rebellion on his right flank, which wants more out of the deal and doesn’t trust the administration. That rebellion is led by Senator Curtis Haas, a Ted Cruz-like figure who leads the tea party.

“I’m sorry,” Haas tells them. “I just can’t do it.”

So Underwood and Mendoza hatch a plan that exploits the mind-bending arcana of Senate procedure to bamboozle Haas and get their bill through. “We make sure that passage of the amendment constitutes the passage of the bill,” Mendoza offers. “We pass the amendment, and then we’re done.”

What does this mean?

Under regular order, a single senator can force 60-vote thresholds for cloture to get on a bill and to end debate before final passage. But the Senate can bring up a bill with an agreement that sets different procedures. So Mendoza proposes a written agreement for this bill that says passage of the retirement age amendment amounts to final passage of the main government funding legislation. Underwood agrees. Once debate on the bill is underway, the amendment can pass with 51 votes, and it can’t be blocked after that. Haas can filibuster the first cloture vote and prevent the whole sequence from going into effect — but there’ll be no more opportunities to filibuster after that if the amendment passes.

Haas ends up opposed to the amendment and Mendoza, worried about getting overthrown as leader, eventually gets cold feet and backs off. He tells Underwood he’s going to pull the amendment or have his Republican members vote it down. So Underwood — unable to persuade him otherwise, and under enormous pressure from President Garrett Walker — resorts to his last-ditch option: swing just enough Republicans to his side, coerce the vote on the amendment and cast the tie-breaking vote, leading to final passage of the bill (given that the Senate has proceeded to the bill under the agreement.)

“We have to get medieval,” Underwood tells an adviser. “Find me the [rules] I can bend.”

The breakup of the Senate appears to be 55-45 in favor of Republicans. Underwood needs to swing five GOP senators or get a bunch of them to abstain. He makes some calls and swings two Republicans by promising goodies for their constituents, and gets six of them to abstain. That’s 47 votes for the amendment, 47 votes against it, and Underwood, as the VP, the deciding vote. Mendoza and Haas, now working together to thwart the amendment, find out that Underwood is poaching Republicans and decide to grind the chamber — and thus the bill — to a halt.

“Forty-nine hours until the recess? We call a name an hour,” says Haas. Mendoza agrees.

Here the Senate is in a quorum call, where the chair calls the roll to make sure there are 51 members present to conduct business. The Republicans are epically slowing it down in an attempt to run out the clock until the recess.

Enter Underwood.

In his capacity as President of the Senate, he steps in as chair and speeds up the roll call. (Some of the senators in the show are based on real-life senators — Brown, Burr, Cantwell, Whitehouse, Wicker and Wyden are among the names called.) Republicans scurry out of the chamber and a quorum is not present. Then Underwood pulls his medieval maneuver.

He recognizes the Democratic minority leader, who motions to compel the attendance of senators. The Democrats back him up, the Republicans (most of which have left the chamber to deny a quorum) motion ‘nay.’ The ‘ayes’ have it, the arrests are ordered by the Sergeant at Arms — the Senate’s law enforcement officer. Underwood gets his quorum.

Haas thinks he still has an ace up his sleeve. He walks up to Underwood, who is still presiding over the vote, and threatens to “filibuster the main bill” even if the amendment passes. Ordinarily he’d be able to do that. But it turns out he didn’t read the agreement to get on the bill, which Underwood then informs him of. “Pay attention to the fine print,” the smug VP tells Haas.

Haas realizes he’s been out-maneuvered. He tries in vain to gum things up by interrupting the roll call vote and proposing an amendment of his own, but Underwood rules him out of order. The amendment passes, and the bill is passed.

Failing to read and understand the text of the agreement was Haas’ fault. But in reality, it’d be seen as a grand betrayal for Mendoza to move forward without being clear and forthcoming with his members. When it’s clear Underwood has won, Mendoza tries to save face by telling Haas that he should have toed the party line. Haas is furious.

Was the whole sequence shady? Yes. Unlikely? Very. But illegal? No.

Sahil Kapur is TPM’s senior congressional reporter and Supreme Court correspondent