Tesla has just posted the third profitable quarter in its history on the back of demand for the Model 3.

The electric automaker revealed that it generated $6.8 billion in revenue in the third quarter of 2018 and secured $311 million in profits. Not only is that the most the company has ever recorded in a quarter, but it is also the first profitable quarter in two years. Tesla also sold $52 million worth of zero-emission vehicle credits to other automakers during that period.

In a letter addressed to investors, Tesla chief executive and chief financial officer Deepak Ahuka said a successful third quarter is a huge moment for the company.

“Q3 2018 was a truly historic quarter for Tesla. Model 3 is attracting customers of both premium and non-premium brands, making it a truly mainstream product.”

The key reason for the improved financial position are the huge leaps made in production of the Model 3. In the third quarter, a total of 56,065 Model 3s were delivered in North America. In addition, the company says it is now locking in margins greater than 20 per cent for the Model 3 thanks to the reduced cost of raw materials and by limiting the number of hours needed to build the entry-level sedan. Tesla now builds a Model 3 quicker than a Model S or X.

Thanks to these improvements, Tesla says it will be ready to start taking orders in Europe and China for the Model 3 before the end of the year.

Despite a successful quarter, it won’t be all sunshine and rainbows moving forward. Tesla currently has more than $10 billion in debt and is still developing the Model Y, Semi and new Roadster. Additionally, it has to build new factories in Europe and China, leading some to suggest it may be forced to raise money soon, The Verge reports.