The 2018 midterms are a massive victory for Democrats, who managed to flip enough Republican-held congressional seats to take back control of the House.

But in a year Democrats had a record-breaking fundraising haul, a heightened level of voter enthusiasm, a strong candidate field and were running against the party of a deeply unpopular president, it’s fair to ask: Why wasn’t the so-called blue wave bigger?

Democrats this year won the popular vote over the Republicans in House races by a 7.1 percent margin, but that didn’t translate to massive gains in actual seats. So far, Democrats have won 28 GOP-held seats for a net gain of 26 seats (they lost two seats previously held by Democrats in Minnesota and Pennsylvania).

Democrats are expected to pick up a handful more seats as votes continue to be counted, but the numbers pale in comparison to the last wave, when Republicans won 63 House seats in 2010. This year, in an election billed as a referendum on President Donald Trump, Trump lost — but only barely. The Republican Party’s fear-mongering about the perils of a liberal America, the explicitly racist ads, and the lies about protecting patients with preexisting conditions all came very close to keeping them in power.

But it’s important to note the result is not because Trump’s agenda has widespread support. Time and time again, the American public has rankled at Trump’s hardline immigration agenda, the GOP’s attempts to cut Medicaid funding and repeal Obamacare, and historically unpopular Supreme Court Justice Brett Kavanaugh. The only reason many lawmakers who back these ideas were able to maintain power is because these are the voices most protected in the electoral process.

For years, Republicans, with their hands on the levers in state legislatures and governors’ mansions, have made it incredibly hard for Democrats to make gains in Congress, redrawing congressional boundaries to favor Republicans and passing laws that make it harder for Americans to vote.

Democrats were able to overcome all that in 2018 — but they have a lot of work to do to replicate the success in the future.

Why a massive blue wave was almost impossible

Democrats had a lot going for them this year. Historically, the party in the White House is disadvantaged in the midterms — and Trump, being as unpopular as he is, gave Democrats an edge on enthusiasm.

But Democrats were always taking on a difficult challenge in 2018. At the end of the day, all the talk of a blue wave boiled down to some simple math: Democrats had to gain 23 Republican-held seats to get back in power, and to do that, it meant they had to win in conservative districts.

Put another way: Winning every single House district that Hillary Clinton won or that Trump won by less than 3 percentage points in 2016, Democrats would have still fallen short of the House majority, as Dave Wasserman of the Cook Political Report wrote for FiveThirtyEight.

For example, take a look at the races Democrats were targeting this year — and even came very close to winning. In Kentucky, Democrat Amy McGrath, an air force veteran with a strong national profile came within 4 points of incumbent Republican Rep. Andy Barr in an urban-rural district that trends toward Republicans by 90 percentage points more than the national average. In Kansas, a similar story; state legislator Democrat Paul Davis came in a close second to a Republican newcomer, army veteran Steve Watkins, in a district Trump won by 19 points in 2016. That’s what Democrats were up against.

Democrats got a taste of how these races would play out in the special election for Ohio’s 12th Congressional District, where the contest to replace Republican Pat Tiberi put Democrat Danny O’Connor within 2,000 votes of Republican Troy Balderson in a district Trump won by 9 points in 2016. O’Connor lost by a bigger margin on Tuesday night. Another example was the special election for Georgia’s Sixth Congressional District to replace Tom Price, Democrat Jon Ossoff outperformed the partisan lean of the district and the past voting patterns, only to lose.

Those races were replicated across the country on Tuesday. But luckily for Democrats, there were just enough races that defied the trend of “moral victories.”

Republicans have been building a strong firewall

To understand why Democrats could only win a slight majority, you have to turn back the clock eight years to the 2010 midterms, when Democrats lost an astounding 63 House seats, giving control to Republicans. Republicans have held the House easily ever since — until now.

Republicans have maintained power in the House even while winning fewer votes than Democrats in House races nationwide, which happened in 2012. It’s because the losses Democrats have experienced go deeper than just the House and Senate. In 2010, Democrats lost control of six governors’ mansions on net, and about 700 state legislature seats; most of these losses were in states like Michigan, Ohio, Pennsylvania, Wisconsin, and Florida, where Republicans gained majorities in all tiers of government.

Republicans’ gains on the state level gave them the power to build electoral firewalls — even in regions that have demographically shifted toward Democrats. In some of the most important swing states, Republicans were able to redraw the congressional maps without Democrats’ input.

It’s because of these gerrymandered maps that we see progressive cities like Austin, Texas, represented by more Republicans in Congress than Democrats, and why overall the median House seat is much further to the right than the nation as a whole.

Republicans have also been able to implement voting laws that suppress turnout — especially among groups that typically vote Democratic.

Look at Georgia, where Democrat Stacy Abrams has not conceded the governor race to Republican Brian Kemp, the Georgia secretary of state who is in charge of overseeing the election, due to a brewing controversy over voter suppression.

Under Kemp’s control, Georgia has removed more than a million names from the state’s voter rolls between 2012 and 2016. And just weeks from Election Day, the Associated Press reported that 53,000 voter registrations — 70 percent of them from black applicants — had been held up for failing an “exact match” process, which requires registration information to perfectly match state driver records. Even closer to Election Day, a federal court ruled that more than 3,000 voters were improperly categorized “noncitizens” by the same “exact match” process, which could have suppressed the vote. Abrams is behind Kemp by less than 100,000 votes.

Similar accounts of voter purges and suppression have been reported in North Dakota, North Carolina, Ohio, Missouri, Virginia, and many more.

Of course, Democratic-run states are also guilty of gerrymandering, just look at states like Maryland. It’s worth noting, however, that this is an operation Republicans have been successfully executing over decades — and they continue to outperform Democrats on basic infrastructure on the state level. In 2018, even as the official Democratic Party arm for state legislature races outperformed its past fundraising levels, Republicans still blew them out of the water.

Losing power at the state level also goes beyond just congressional maps and voter laws; it oftentimes leads to a skeletal state party infrastructure, a depleted pool of political candidates, and disadvantaged voter turnout operations.

Democrats have work to do. They made some progress.

There were some glimpses of hope for voting rights activists Tuesday night, however.

Florida passed a ballot initiative that will restore voting rights to more than 1 million ex-felons in the state. As Vox’s German Lopez wrote, Florida had disenfranchised more possible voters than in any other state; more than 10 percent of all potential voters and more than 21 percent of potential black voters in Florida have been unable to vote because of felony records.

In Michigan, an anti-gerrymandering ballot initiative also got approved, which would create an independent commission of an equal number of Democrats, Republicans, and five individuals who won’t identify political leaning, to draw the congressional maps.

And as for Democrats, they did make some gains on the state levels that will help them take back power in these decisions.

Democrats were able to win in an uphill battle — but if 2018 proved anything, it’s that the Republican firewall is strong. And in the years ahead, how Democrats organize down the ballot will prove to be just as important as the fight to control Congress.