As the Tesla Model S faltered, Detroit began to rethink how to build its next-generation electric car, a car that would rival the most expensive electric vehicles on the market, the BMW 5 Series.

But the cost of building that car, and the company’s reluctance to expand its electric vehicle lineup, left it scrambling to figure out how to pay for the cost overruns that had kept it from achieving the level of sales growth that it’d hoped.

By the time Tesla and other electric car makers were forced to slash their prices in response to those losses, the company was in trouble.

The Model S’ demise in 2016, after nearly two decades of sales, led to Tesla and its parent company, the electric carmaker SolarCity, to sell off a chunk of its business to acquire rival competitor SolarCity.

Tesla had been on a tear since its 2009 IPO, making huge profit margins on cars and building a fleet of new electric vehicles, but in 2017 the company had been hit by a series of costly financial missteps, including a $2.5 billion loss on its capital investment in battery startup SolarCity that led to the company being forced to scale back its efforts and reduce production of the cars it had been building.

SolarCity’s CEO, Lyndon Rive, who had been a major investor in Tesla, was let go in 2018 after he admitted to mismanaging his company and to having violated company rules, including not disclosing the cost savings from investing in SolarCity on his own.

The news was greeted with dismay among Tesla fans, who have long complained about how the company has consistently underpriced its cars and failed to produce them on time, despite a decades-long focus on building its cars at a rate of roughly 30,000 per month.

In the wake of Tesla’s loss, the solar company, which had sold about 1.7 million Model S sedans and the 1.9 million electric cars the company produced in 2017, decided to sell itself off and turn its assets into a company focused on building solar power.

Tesla will retain the solar power business, but will sell its battery business to SolarCity as part of a transaction valued at about $1 billion, SolarCity CEO Ed Kranz said in a statement.

“We believe the SolarCity transaction will benefit the Tesla community in ways that will be positive for the long-term future of the company,” Kranp said.

“The transaction will enable Tesla to continue building the electric vehicle ecosystem that will enable it to accelerate its business growth while delivering a competitive edge for its customers.”

SolarCity has been a big player in the solar market since the late 1990s, when it was founded by billionaire entrepreneur Peter Rive and built a solar panel factory in Reno, Nev., that now produces solar panels for about a third of the U.S. market.

But as the industry has grown, the market for solar panels has also grown rapidly, with companies like SolarCity and Panasonic, which makes solar panels, both investing billions in new plants in Nevada and elsewhere.

SolarWorld, the largest manufacturer of solar panels in the U, had $1.9 billion in cash and stock at the end of 2017, according to the most recent financial filings from the company.

That was up nearly 40% from the end a year earlier.

SolarTech, the nation’s largest solar panel manufacturer, had more than $1 trillion in cash at the same time.

Solar companies have been the targets of a series on their profitability and share prices in recent years.

Last year, solar companies’ share prices declined nearly 9% after they filed for bankruptcy protection.

Solar’s share price fell by nearly 10% last year, according the S&P 500.

Tesla’s stock dropped nearly 11% in 2018, the last year that SolarCity reported financials.

Solar Tech also reported a $3.3 billion loss in 2018.

Solar industry analyst Jefferies forecasts SolarCity will see its profit decline to about $3 billion in 2019 from about $8 billion in 2018 as the solar industry struggles with the cost competition and the impact of climate change on its business.

SolarPower, the other company in SolarWorld’s portfolio, also saw a loss in 2019.

Tesla, SolarTech and SolarCity declined to comment for this story.

Tesla said in an interview that the SolarPower deal, in which it will sell off its entire solar business, will allow it to focus on a new product line called Solar Power.

Tesla says it will build a new battery manufacturing facility in Michigan and that the deal will allow Tesla to build “much faster” solar cells and batteries for its vehicles.

“That new battery technology will provide much faster vehicle production,” Elon Musk said in the statement.

But many analysts say that the new manufacturing line won’t provide the same level of battery production and storage capacity that Tesla has provided for decades.

Tesla has built more than 1.5