Tesla made and delivered more cars in the second quarter of 2019 than it did in any other quarter in company history, but still lost $408 million, according to a new filing with the Securities and Exchange Commission. That’s an improvement over the unexpectedly big $702 million loss Tesla posted in the first quarter of 2019, but it means the Model 3 is still not successful enough to lift the company out of the red for good.

Tesla also announced that longtime chief technology officer JB Straubel is stepping down after serving in the role for some 15 years. “I’d like to thank JB for his fundamental role in creating and enabling Tesla,” CEO Elon Musk said on a call with analysts Wednesday evening. “If we hadn’t had lunch in 2003, Tesla wouldn’t wouldn’t exist, basically.” (Straubel and Musk didn’t found Tesla, but consider themselves co-founders.)

The record quarter did help the company generate $6.3 billion in revenue, and $117 million of the loss was attributed to restructuring charges related to layoffs and store closings. Tesla also shared that it finished the quarter with $5 billion in cash, the “highest level in Tesla’s history,” largely thanks to a $2.7 billion capital raise in May. “We believe our business has grown to the point of being self-funding,” the company wrote.

Tesla finished the quarter with more cash on hand than ever

One thing that’s complicating the company’s pursuit of profit is that sales of the Model S and Model X have largely stalled. On one hand, that’s to be expected, as they are older models that cost tens of thousands of dollars more than the newer Model 3. But they also make more money per car for Tesla, and so the dip in popularity is eating into the company’s overall margins for its automotive products, which dropped to 18.9 percent from 20.2 percent in the first quarter.

“There’s probably a bit too much focus on [Models] S and X,” Musk said the call. “But the story for Tesla in the future is, fundamentally, the Model 3 and Model Y.”

Tesla did upgrade both the Model S and Model X in April with tech from the Model 3 that dramatically increased their overall range and improved charging speeds. But rumors of a full refresh of the company’s flagship vehicles were recently squashed by Musk.

“There may be a false expectation in the market that there’s, like, some big overhaul coming for S and X which then, you know, could cause people to hesitate to buy if they think there’s like some radical redesign coming, which is why I emphasized publicly that this is not the case,” Musk said on the call Wednesday. “The Model S and X today are radically better than the ones that when we first started production, especially the S. Like, a 2013 or 2012 Model S, compared to todays Model S — it’s night and day.”

Musk said there “may be a communications issue where people don’t realize just how much better the S and X are today,” and that Tesla wants to address that communications issue. He also said he thinks Tesla can get to 25 or 30 percent gross margin on its vehicles within a year if the company is able to roll out more features in its “full self-driving” Autopilot package. Since most customers haven’t opted for that yet, Musk said, there’s a ton of money left to be made if Tesla can convince existing owners to pay a few thousand dollars for what amounts to an over-the-air injection of new code.

Tesla stumbled into 2019 despite snatching success from the jaws of “production hell”

The Model 3 was the best-selling EV in the world in 2018, and helped Tesla record back-to-back profits for the first time in the company’s history. The company sold around 250,000 vehicles over the entire year, essentially doubling the number of Teslas on the road.

But despite snatching success from the jaws of “production hell” last year, Tesla stumbled into 2019. The company laid off 7 percent of its workforce in January 2019 — a move Musk said in 2018 he hoped to never have to do again. Then Tesla cut even more workers in February when it announced a plan to close most of its stores in order to cut costs enough to deliver a Model 3 with a base price of $35,000. (The company quickly reversed that plan and decided to leave some of those stores open.) It also kept changing prices on all of its cars, much to the dismay of many owners.

The company started facing questions about North American demand for its vehicles earlier this year, too. Tesla’s vehicles lost eligibility for the full $7,500 federal EV tax credit starting January 1st. (As of today, buyers can only get $1,875 from the federal government. The credit fully goes away for Teslas starting in 2020, though many states still offer incentives.) The company also turned some of its attention away from the US market at the beginning of the year in order to start shipping Model 3s to Europe and China, two key new markets.

Those questions seemed prescient, because in April, the company announced its first drop in quarterly deliveries in nearly two years. Tesla had one of its worst financial quarters ever, losing $702 million — $121 million of which was attributed to the pricing changes. Tesla told investors to expect another loss in the second quarter as well, even though Musk had said in February that the company would return to profitability by then. The share price of Tesla’s stock dropped more than $150 between January and June (though it has since rebounded).

A flurry of all-staff emails written by Musk were leaked in May. In one of them, he announced drastic new cost-cutting measures that went beyond the ones the company implemented in 2018. But in the others, Musk tried to rally the company’s employees. He hinted that Tesla, buoyed by steadier deliveries in Europe and China, might be able to set a record for deliveries in the second quarter.

On July 2nd, the company announced just that: Tesla had beaten its own records for quarterly production and deliveries, which were set in the fourth quarter of 2018.

Tesla plans to deliver between 360,000 and 400,000 cars across all of 2019, and thanks to its slower first quarter, will have to keep operating at its torrid second-quarter pace in order to do that.

The company is nearing the completion of its third Gigafactory, located in China. Getting production up and running there could help the company meet, or maybe even beat, that delivery goal for the year. Despite a recent downturn, China is still the biggest market for electric cars in the world. Making cars locally will help Tesla get around existing import taxes on the Model 3, which could theoretically boost sales there.

“Tesla’s rebound in sales in Q2 was encouraging, but the company’s total sales are still down year-to-date, and they are far more heavily skewed to the Model 3 versus Model S or X in 2018,” Karl Brauer, executive publisher at Kelley Blue Book and Autotrader, said in a statement. “That could be at the heart of the financial miss in Q2, and it could prove difficult to address with the current model mix. The Model Y and Chinese production will both contribute to profit, but not in the near term, suggesting 2019 will be a tough year for Tesla’s financials.”