A homeless man who pleaded guilty to trafficking cocaine had his case dismissed after the substance turned out to be powdered milk.

Cody Gregg told a judge he entered the plea so he could get out of the Oklahoma County jail.

Gregg, 26, pleaded guilty last week to possession of cocaine with intent to distribute and was sentenced to 15 years in prison, court records show. He asked to withdraw his plea after receiving a negative lab report. Oklahoma County District Judge Timothy R. Henderson granted the request on Thursday and the case was dismissed the next day.

Gregg had been in Oklahoma County jail since his arrest in August. He was released Friday, according to jail records.