Updated

LOS ANGELES -- A Los Angeles judge rejected Charlie Sheen's application for full custody of the twin sons he shares with his estranged third wife, Brooke Mueller, because he bragged about his drug use, TMZ reported Wednesday.

Judge Hank Goldberg ordered Tuesday's court hearing to be held behind closed doors, saying it was "best for the children."

But sources familiar with the hearing told TMZ that Goldberg rejected Sheen's request to strip Mueller of custody of the two-year-old twins, Bob and Max, because he was no better at looking after them.

"Judge Hank Goldberg was well aware Brooke had relapsed into drug use, but the judge was equally disturbed by Charlie's substance abuse and the fact that he bragged about it," sources told the gossip site.

The judge "felt both Brooke and Charlie had problems, but the twins were adequately protected by the nannies, relatives and other support staff," the sources added.

The couple will continue to share custody of the tots under an existing arrangement.

Neither Sheen nor Mueller were talkative as they emerged from court, but Mueller, appearing jovial and flanked by her parents, sardonically said she felt "excellent" when throngs of photographers pressed in around her.

Mueller was believed to be struggling with sobriety and refused to undergo a drug test last week, violating part of the custody arrangement. She spent Monday at a rehab facility as she reportedly tried to get clean.

Sheen's ex-wife, Denise Richards, offered to take temporary custody of the boys, and Mueller's mother, Moira Fiore, also stepped forward to look after the toddlers, the celebrity website reported.

Sheen, 45, with one "goddess" in tow for his court appearance, appeared at ease and dapper in a suit and tie.

He headed straight to the airport after the court appointment to make a cross-country flight for his "My Violent Torpedo of Truth/Defeat Is Not an Option" show in Washington, D.C.