BMW said it generated more cash than expected last year, joining German peer Volkswagen in posting upbeat preliminary earnings after sustaining their recovery from coronavirus disruptions.

Automotive free cash flow rose to 2.8 billion euros ($3.4 billion) in the final three months of 2020, almost double the year-earlier period, BMW said in a statement Wednesday. The company reiterated that margins will be at the higher end of a range of as much as 3 percent.

BMW and VW’s sales both rebounded after the first half of last year, with demand coming back particularly strong in China. Still, coronavirus lockdowns weighed on full-year shipments, and Daimler’s Mercedes-Benz maintained its leadership of the global luxury-car segment for a fifth consecutive year.

While BMW is doing well in China — its largest market — the automaker is under growing pressure there as upstarts including Tesla, Nio and Li Auto gain share.

BMW is responding to the threat by expanding its electric offerings, with the iX SUV and the i4 sedan expected to go on sale this year and in 2022, respectively.

BMW also benefited from better-than-expected results from remarketing used cars, a segment bolstered by consumers seeking alternatives to public transport because of the pandemic. That market, along with what the company called “focused” management of inventories, helped increase free cash flow to about 3.4 billion euros last year.

The company this week was among a group of 42 companies approved to get about 2.9 billion euros in state aid for battery projects that will strengthen Europe’s position in the race to produce more electric vehicles.

BMW also will invest a three-digit million euro amount in internet marketing and sales processes as it bets online purchasing will help compensate for pandemic-related dealership closures in its major markets.

The company is scheduled to publish detailed full-year earnings on March 17.