Elon Musk has offloaded almost $7 billion of Tesla stock to avoid an emergency sale later to raise finance if a court decides he must go through with a deal to buy Twitter.

Musk raised $6.9 billion by selling 7.9 million shares in the EV firm, cash he desperately hopes he won’t need. Earlier this year Musk agreed to buy the social media company for $44 billion and raised $8.5 billion from selling Tesla shares in April to finance the deal. But last month he announced he was pulling out of the Twitter buyout, claiming that management hadn’t been clear with how many user accounts were real, and how many were bots.

Twitter reacted by suing Musk to force him to go ahead with the takeover. The case will be decided in court in October, and although Musk is being bullish about his chances of winning, he knows he needs to have his financial ducks in a row should he end up on the losing side.

“In the (hopefully unlikely) event that Twitter forces this deal to close *and* some equity partners don’t come through, it is important to avoid an emergency sale of Tesla stock,” Musk said in a tweet on Tuesday.

Related: Elon Musk Trolls The Slow Production Rate Of Lucid Motors On Twitter

When asked by a Twitter user if Musk would buy Tesla stock again if he wins his case and is not forced to buy the platform, Musk replied that he would. But even if that doesn’t happen, Musk still has plenty of fingers in the Tesla pie. CNN Business reports that the 7.9 million shares Musk has sold represent only 3 percent of the Tesla shares and options the CEO holds. Musk still owns 155 million Tesla shares and also has options to buy almost 100 million additional shares at well below the current market price.