Tesla did not expect such a rave response for the Model 3. When the company started taking reservations for its $35,000 electric car in summer 2016, its cheapest-ever vehicle, executives predicted somewhere around 50,000 orders. By the end of that week Tesla had accumulated a staggering 325,000 orders, a figure that would rise to nearly 500,000 in the following 12 months.

A Wired feature published Thursday reveals how the company, which had only sold around 150,000 cars ever since its first vehicle hit the roads in 2008, unexpectedly found itself at the heart of a major restructuring. It was no longer a niche automaker, but a mass producer of electric vehicles. It was a bold challenge, and a sudden intervention from CEO Elon Musk placed the whole project in jeopardy.

Musk, the report claims, told executives in a meeting that he’d had a dream recently about a fully-automated future factory, with robots whizzing around at speed. It was an idea he’d been developing for a while. Musk referred to his vision as “an unstoppable alien dreadnought,” evoking images like those seen in 2017 video game Dreadnought:

Dreadnought
That's one big factory.

*See more:

Musk mentioned his “alien dreadnought” vision to investors in an August 2016 conference call. In subsequent discussions, he would refer to the Nevada-based Gigafactory as “machine that builds the machine.”

Unfortunately, Musk’s high dependence on automation came at a heavy price. While the company originally planned to produce 5,000 cars per week by December 2017, six months after the start of production, Tesla only produced 202 Model 3s per week in the last quarter of that year. In April, Musk eventually admitted that “excessive automation…was a mistake” and that “humans are underrated.” In an interview with 60 Minutes last week, Musk revealed that the firm had been losing around $100 million per week in its toughest moments.

“It is often a choice of no sleep or Ambien,” Musk told the New York Times in August, as he described 120-hour work weeks and sleeping at the factory on his birthday.

At the end of June, Tesla pulled through. The company produced 5,000 Model 3s in one week, finally meeting its December 2017 goal. In October, Tesla posted its first profitable quarter in two years with $311 million, its highest quarterly profit share ever and only the third in its history.

The focus has now shifted to Tesla’s next tasks, like the Model Y mass market sports utility vehicle and international expansion of the Model 3. The vehicle is now crushing the competition, and the future looks bright. Musk’s original vision of a space-age superfactory nearly ended the Model 3 before it could really get started.

Related video: Northvolt Wants to Build a Gigafactory of Europe