Kodak Black is headed back to rehab.

The rapper, whose legal name is Bill Kahan Kapri, appeared in Broward County Court on Tuesday where a judge ordered him to a drug rehabilitation facility for 30 days after he allegedly tested positive for fentanyl while awaiting trial on a drug trafficking charge.

Kodak violated his bail conditions when he failed to submit to a drug test on Feb. 3. When he did submit a sample on Feb. 8, it came back positive with traces of fentanyl. As a result, a warrant was issued for his arrest.

During Tuesday’s hour-long hearing, his attorney, Bradford Cohen, suggested that a “star-struck” private lab technician may have mixed up the urine sample or paperwork with someone else’s. The tech who collected the sample testified in court that it’s possible the lab made a mistake.

“I think to rely on that, to take somebody into custody, it would be a great miscarriage of justice,” Cohen said, according to the Miami Herald.

The judge suggested that Kodak take a hair test, which is used to detect drug use over the past 90 days, but he declined. On Instagram, Cohen said that the Pretrial Services Program of the Broward Sheriff’s Office doesn’t provide hair sample services.

While speaking to the judge, Kodak said he didn’t deserve to be in jail. “All the good deeds I do, all the good things I do, it never goes as viral,” he said. “I don’t know why [they] are so hungry to see me in jail.”

Broward County Judge Barbara Duffy allowed the rapper to begin rehab on March 7 so he could perform at Rolling Loud California this weekend.

“You better get it together,” Duffy told Kodak, who plans to donate a portion of his check from the festival to his scholarship fund.

“I am glad @kodakblack will get an opportunity to take a break from his hectic schedule and focus on his physical health,” added Cohen. “Great kid, great philanthropist and as usual a portion of his Rolling Loud pay check will go to the Meadow Pollack scholarship fund at Nova Southeastern Law School, that he set up last year.”