NEW YORK (AP) — A judge Wednesday hiked Harvey Weinstein’s bail over allegations he mishandled or disabled his electronic ankle monitor dozens of times in recent months.

Judge James Burke gave Weinstein three options to cover a new bail of up to $5 million and warned the disgraced movie mogul that he’ll face jail if other issues crop up.

Weinstein, who had been free on $1 million bail, agreed to meet the obligation by putting up $2 million in cash and other assets through a bail bondsman.

Weinstein, 67, leaned on a walker as he came and went from a New York City courthouse for a hearing on prosecutors contention that he had tinkered with the monitoring device.

He looked frail and pained, as he did at a court appearance last week.

Weinstein’s lawyer said he is scheduled for back surgery Thursday to relieve pain from an August car crash and that he will recover in time for the Jan. 6 start of his trial on rape and sexual assault charges.

Burke cautioned Weinstein against any last-minute surprises as the trial draws near.

“If you have any further medical issues, the court will not be terribly understanding,” Burke said.

Weinstein indicated the surgery and new bail arrangement would guarantee he appears at his trial.

“This ensures I am here Jan. 6,” Weinstein said. “This is a good thing for you.”

Weinstein has pleaded not guilty to charges he raped a woman in a Manhattan hotel room in 2013 and performed a forcible sex act on a different woman in 2006.

He maintains that any sexual activity was consensual.

Weinstein’s lawyer, Donna Rotunno, said he is “looking forward” to the trial. She said they plan an aggressive defense, but said vigorous cross-examination shouldn’t be viewed as victim shaming.

“Just because someone makes a claim doesn’t make it true,” Rotunno said.

Burke offered Weinstein three bail options because of reforms to New York’s bail system that are set to take effect on Jan. 1.

Other than using a bail bondsman or paying $5 million cash, Weinstein could have used collateral to secure 10% — or $5 million — of a $50 million bond with collateral.

Weinstein bail bondsman Ira Judelson’s clients have included mixed martial arts fighter Conor McGregor and former International Monetary Fund honcho Dominique Strauss-Kahn.

One of Judelson’s associates outside the courthouse wore a sweatshirt with the slogan, “Got Bail?”

Prosecutor Joan Illuzzi first raised Weinstein’s alleged bail violations at a hearing last Friday. She said that he’d left his whereabouts unrecorded for hours at a time by repeatedly, purposely leaving at home a piece of the monitoring technology that keeps the ankle bracelet activated.

Illuzzi said Wednesday there were 57 violations in less than two months.

Rotunno has denied it was anything deliberate, blaming “technical glitches” like dead batteries. She said the issues had nothing to do with manipulation of the bracelet, though she acknowledged that on at least one occasion, he’d forgotten part of the device at home.

But on Wednesday, Illuzzi told the court that the person monitoring Weinstein does not believe the problems were due to technical glitches, but rather intentional acts by Weinstein because he “didn’t want anyone to know where he was.”

In recent months, Weinstein has been spotted hobnobbing at Manhattan nightclubs and getting jeered at a recent actors showcase.

While the monitoring now appears to be working, Illuzzi said she thought that was because of the threat of new bail.

“I don’t think it was the adding of the extra batteries,” Illuzzi said. “It was Mr. Weinstein’s panic that the court might change the bail.”

After the hearing, Rotunno countered Illuzzi’s assertion.

“There were no violations. These were technical issues related to a battery,” she said. “Ms. Illuzzi makes mountains out of mole hills.”