DETROIT (AP) — Electric car maker Tesla Inc. is laying off about 3,600 workers mainly from its salaried ranks as it slashes costs in an effort to deliver on CEO Elon Musk’s promise to turn a profit in the second half of the year.

In an email to workers on Tuesday, Musk said the cuts amount to about 9 percent of the company’s workforce of 40,000.

Tesla would not say how much money the layoffs would save, but said no factory workers would be affected as the company continues to ramp up production of its lower-priced Model 3 compact car.

The move is part of an organizational restructuring that Musk announced earlier in the year.

“Tesla has grown and evolved rapidly over the past several years, which has resulted in some duplication of roles and some job functions that, while they made sense in the past, are difficult to justify today,” Musk wrote in the email. He thanked departing employees for their hard work and said Tesla is providing “significant salary and stock vesting” to those being let go, based on their length of service.

Tesla has not made an annual profit in its 15 years of doing business, and it has posted only two quarterly net profits.

At the company’s annual shareholder meeting earlier this month, Musk said he expected the Palo Alto, California, company to post a quarterly profit during the July-September period. For nearly all of its history, Tesla has put up losses while investing heavily in technology, manufacturing plants and an extensive car-charging network.

It’s not the first time Tesla has laid off workers. The company let go of 400 to 700 workers last fall after completing annual performance reviews, and it laid off a small number of workers back in 2008.

Musk wrote in the email that the company will never achieve its mission to help move the world to cleaner energy “unless we eventually demonstrate that we can be sustainably profitable.”

The company is making the move now so it never has to do it again, he wrote. Tesla still has a significant need for production workers as it tries to reach Model 3 manufacturing targets, he wrote in the email.

The layoffs come in engineering, sales and other front-office functions, but the company says the remaining workforce is large enough to accomplish Musk’s lofty goals of rolling out a semi, pickup truck and a new SUV in the coming years.

Tesla shares rose 2.5 percent to $340.34 in afternoon trading, after reaching as high as $354.97 around noon.

Musk also announced that the company’s solar panel unit has decided to end its agreement to sell via Home Depot stores so it can focus on sales in Tesla’s company stores and online. A majority of Tesla employees working at Home Depot will get offers to work in Tesla’s own stores.

Consumer Edge Research Analyst James Albertine wrote in a note to investors that he views the moves “as a positive in helping Tesla track toward profitability later this year.”

He wrote that reaching Musk’s Model 3 production goal of 5,000 vehicles per week by the end of June is still the primary driver of profitability. “A focus on ‘getting lean’ is a positive with respect to Tesla’s guidance for achieving consolidated profitability in 2018, in our view,” he wrote.

The Model 3 starts at $35,000, but lower-priced configurations are not available yet. It can easily top $50,000 with options.