With a pledge of future profitability and an apology for past bad manners, Tesla CEO Elon Musk was upbeat in his conversation with analysts during a second-quarter conference call Wednesday.

Tesla shares soared as much as 11 percent in after-hours trading. The stock has been under pressure for some time as investors have worried about the cash the company was burning and whether it would be able to sustain its profitability.

The electric car maker's second-quarter loss was wider than analysts expected, but the company backed its prior forecast that calls for profitable third and fourth quarters.

"From an operating plant standpoint, from onwards I really want to emphasize our goal is to be profitable and cash flow positive for every quarter going forward," Musk said on the call. He added that recessions, or force majeure events could derail the plan but the goal is to be achieving positive GAAP income and cash flow "every quarter from here on out."

Increased rates of production, improving margins, and cost cutting is helping Tesla hit its goal.

Here's how the company did compared with what Wall Street expected:

Losses: $3.06 per share vs. $2.92 per share forecast by Thomson Reuters

Revenue: $4.00 billion vs. $3.92 billion forecast by Thomson Reuters

One big step it made was completing its major cost restructuring plan in the second quarter, the company said. Tesla had $2.2 billion in cash on hand at the end of the quarter, and expects its cash reserves to grow in the second half of the year. It also now expects to spend less that $2.5 billion in capital expenditures in 2018, far below the $3.4 billion it spent in 2017.

This quarterly update is a crucial one for Tesla. Investors have growing concerns about Tesla's ability to be consistently profitable, reported quality problems with its cars, and overall demand for the Model 3, which is the company's biggest bet by far.

Tesla said it produced 53,339 vehicles in the second quarter and delivered 22,319 Model S and Model X vehicles and 18,449 Model 3 vehicles, totaling 40,768 deliveries.

The company said in July it was able to repeatedly hit its target of producing 5,000 Model 3 vehicles per week.

Production, though, is many months behind schedule and the company has resorted to setting up assembly lines in temporary tent structures.