Democrats appear to have avoided a political nightmare Tuesday in California, with a Democratic candidate getting on the ballot in three races that could be critical to winning a House majority in November.

For the past few months, Democrats had been sweating the possibility of political disaster. California’s 39th, 48th, and 49th districts in Orange County represented three of their top pick-up opportunities. But the slew of Democratic candidates in each race, they feared, could splinter the vote, resulting in two Republicans advancing to the general election via California’s jungle primary system.

Democratic efforts to avoid such a scenario appear to have been successful. Democratic candidates are on track to advance in all of those races, though with results still being counted, it’s not entirely certain who.

It is a relief for Democrats, who need to win a net of 24 seats in November to gain a majority in the House. Some of their best bets for doing so are the 23 districts where both Hillary Clinton and a Republican House member won in 2016. Seven of those are in California — five in Orange County alone.

None of those were anything close to sure bets to begin with. But now, at least, none of them are off the table entirely.

Democrats sprung into action earlier this year, as it became apparent they had a problem of their own making. Outsized enthusiasm in the wake of Donald Trump’s election has been a boon for Democrats across the country, resulting in strong fundraising and a surge of volunteers and activism. It has also given Democrats a stable of strong recruits — even in districts where they have long struggled to recruit any candidate, much less a good one.

But in California, that wealth of riches proved a double-edged sword. The sheer number of Democrats in each race raised the specter of all these candidates splitting the Democratic vote so many ways that two Republicans would be able to go through.

Democrats did what they could to alleviate the situation, encouraging candidates who appeared to have little chance at winning to exit the race. The Democratic Congressional Campaign Committee and House Majority PAC, the super PAC allied with the DCCC, ran ads attacking Republican candidates in those races, trying to lower their vote share.

Still, it was an uphill battle. In the 48th District, for instance, where Democrats hope to unseat Republican Rep. Dana Rohrabacher, there were eight Democrats on the ballot. Three of those had dropped out of the race before Election Day, acknowledging the political realities, but they had done so too late to take their names off the ballot. The DCCC ultimately picked a favorite candidate — Harley Rouda — in an effort to bring order to the mayhem. The group did the same in the 39th District, adding Gil Cisneros to its Red to Blue list. Both Cisneros and Rouda, as of Wednesday morning, held second place in their races.

That could change as California continues to count outstanding ballots. Rouda declared victory late Tuesday night, but he is virtually tied with Hans Keirstead, a Democrat who had the California state party’s backing, behind Rohrabacher. Scott Baugh, a Republican candidate in that race, is currently in a close fourth place.

In the 39th District, currently held by retiring Republican Rep. Ed Royce, Republican Young Kim — who had Royce’s backing — came in first. If results stay as they are, she will face Cisneros. Further south, in the 49th District, where Democrats hope to flip the seat after Republican Rep. Darrell Issa announced he would retire, the Republican candidate will be Diane Harkey, who had the backing of Issa and House Majority Leader Kevin McCarthy. Democrat Mike Levin is currently in second place.

The national map did change earlier this year in Democrats’ favor, giving Democrats some buffer beyond the 23 districts Clinton won. After court-mandated redistricting in Pennsylvania, Democrats appear likely to pick up at least three Republican-held districts in the state, while at least four more are now on the table. Still, staying competitive in Orange County could be vital for the party.