Tesla reported Wednesday a wider-than-expected loss of $408 million, or $2.31 per share, and generated $6.3 billion in revenue in the second quarter despite record deliveries of its electric vehicles.

Earlier this month, Tesla reported it delivered 95,200 of its electric vehicles in the second quarter, a dramatic reversal from a disappointing first period. Those numbers have been since adjusted to 95,356 vehicles. The record-breaking figures stood in stark contrast to the company’s first quarter delivery numbers when it reported deliveries of 63,000 vehicles, nearly a one-third drop from the previous period.

Analysts surveyed by FactSet were expecting an adjusted loss of 35 cents a share on revenue of $6.47 billion. The net loss in the second quarter included a $117 million of restructuring and other charges, the company said in its earnings report.

A recovery from Q1

While earnings missed Wall Street expectations, Tesla has recovered since the first quarter of the year when it posted a loss of $702 million, or $4.10 a share, after disappointing delivery numbers, costs and pricing adjustments to its vehicles cut into profits. When adjusted for one-time losses, Tesla lost $494 million, or $2.90 a share in the first quarter.

Revenue has also jumped 40% from $4.5 billion in the first quarter to $6.3 billion in the second period thanks again to the increase in sales, particularly for the Model 3.

The company is also sitting on substantially more capital. Tesla ended the second quarter with $5 billion in cash and cash equivalents — the highest level in Tesla history — a figure that was boosted by a public offering of equity and convertible bonds, which netted $2.4 billion.

Tesla generated free cash flow (operating cash flow less capital expenditures) of $614 million in the second quarter compared to a loss of $920 million in the first quarter.

Tesla’s financial picture has also improved when compared to the same quarter in 2018, when it posted a loss of $718 million, or $4.22 a share, on $4 billion of revenue.

Automotive gross margins

Notably, the company’s automotive gross margins have narrowed to 18.9% in the second quarter compared to 20.6% in the same quarter last year based on generally accepted accounting principles. Tesla said it will continue to make progress reducing the cost of the product, including through volume growth, lowering material cost, reduction of labor hours per vehicle and reduction of logistics costs.

Tesla said that Model S and Model X gross margin were impacted by pricing actions on vehicles with the prior powertrain version. Inventory of these vehicles has decreased materially into the third quarter, the company added.

Tesla has previously said it is targeting 25% automotive gross margins for Model S, Model X and Model 3. But that didn’t happen in the first quarter and it slid further in the second quarter.

Tesla’s margins were buffeted in the past by sales of the higher-priced (and better margin per vehicle) Model S and X. Now Tesla is in an awkward spot where demand for the Model 3 hasn’t been enough to stave off contracting margins caused by a decline in Model S and X sales. Model 3s have a lower profit margin per vehicle than the S or X.

Sticking to guidance

Tesla noted that its Fremont, Calif. factory “has demonstrated capability of a 7,000 Model 3 vehicles per week run rate, which the company says it continues to work to increase. Tesla said it aims to produce 10,000 total vehicles of all models per week by the end of 2019.

Tesla is sticking to its previous guidance of 360,000 to 400,000 vehicle deliveries this year.

The automaker also expects positive quarterly free cash flow with an important caveat that it could reverse into loss around the launch and ramp of new products. Tesla is planning to produce the Model Y by fall 2020 and it has a slate of other products on the docket, including the new Roadster and Tesla Semi.

Tesla has reduced its guidance for capital expenditures to between $1.5 billion and $2 billion.