Twitter CEO Jack Dorsey once said that Tesla and SpaceX CEO Elon Musk is the most exciting and influential person on Twitter. Musk loves to kibbitz with fans, answering questions about his tech, making reading and music suggestions, and solving customer-service issues in real time. But court documents released late Monday show Musk and associates scrambling to deal with what one might call excessive openness on Twitter—openness that has gotten Musk in (more) legal trouble.

According to emails included in the filing, Musk has regrets. “I'm a fucking idiot,” he wrote to a public relations adviser in September 2018.

Stay in the know with our Transportation newsletter. Sign up here!

The court filings are from defamation lawsuit filed by a Thailand-based British cave expert named Vernon Unsworth, who aided in the rescue of a Thai youth soccer team and their coach in July 2018. Unsworth’s lawyers contend that Musk is “a thin-skinned billionaire” who “orchestrated a malicious, false, and anonymous leak campaign in the UK and Australian press” that sought to paint Unsworth as a pedophile. The drama included a $52,000 private investigation by a convicted felon, as well as a Musk associate acting under an assumed name.

Musk had his own plan to rescue the soccer team, involving a child-sized mini-submarine. Unsworth told a CNN reporter that Musk’s plan was a publicity stunt that wouldn’t work. Musk, he said, could “stick his submarine where it hurts.”

A few days later, Musk saw Unsworth’s comments online, and spent less than an hour searching the man’s name online, Musk said in an August 2019 deposition. The billionaire was frustrated, he told lawyers during the deposition: “Who the hell is this guy, and what the hell is he doing insulting me, insulting everything my team did, the hard work everyone put in to try to help these kids?” he said. After finding an article linking Unsworth’s home city of Chiang Rai with the sex trade, Musk defended his submarine plan in a series of tweets to his 20 million followers, and called Unsworth a “pedo guy.” The CEO apologized for the tweets three days later.

But Musk didn't let the matter drop there, according to court filings. According to the court filings, a British man named James Howard-Higgins reached out to Musk in August 2018 about Unsworth, claiming to be a private investigator and alleging the diver had “skeletons in his cupboard.” Musk allegedly passed Howard-Higgins’ information to the head of his family office, a man named Jared Birchall. Birchall assumed the name James Brickhouse for his dealings with Howard-Higgins, and as Brickhouse, used more than $50,000 of Musk’s funds to hire the investigator to dig into the expat’s history.

Musk said Howard-Higgins passed Birchall information alleging that Unsworth had married a girl when she was as young as 12, though Unsworth’s lawyers say Howard-Higgins never told Birchall that Unsworth’s wife was any younger than 18 or 19 at the time of their marriage. (In fact, the diver’s wife was 32 when they met, the lawyers say.) BuzzFeed News later revealed that Howard-Higgins was in fact a fraud who had previously been convicted for stealing from a business partner, and is now in prison for violating the conditions of his parole. Either way: In August 2018, Musk responded to a BuzzFeed News reporter’s email about the “pedo guy” tweet by alleging that Unsworth was a “child rapist.” The reporter published Musk’s allegations in an article—allegations, Unsworth lawyer’s say, that are false.