A doctor who prosecutors said ran a medical practice in Virginia like an interstate drug distribution ring was sentenced on Wednesday to 40 years in prison for illegally prescribing opioids.

Dr Joel Smithers was sentenced in US district court in Abingdon. Judge James Jones sentenced Smithers to 40 years. He faced a mandatory minimum sentence of 20 years and a maximum of life.

Smithers was convicted in May of more than 800 counts of illegally distributing opioids, including oxycodone and oxymorphone that caused the death of a West Virginia woman.

Authorities say Smithers prescribed more than 500,000 doses of opioids to patients from Virginia, Kentucky, West Virginia, Ohio and Tennessee while based in the small western Virginia town of Martinsville from 2015 to 2017. Martinsville has a population of roughly 13,000.

US attorney Thomas Cullen said the sentence, while severe, “serves as just punishment” for Smithers’ actions.

“This physician perpetuated, on a massive scale, the vicious cycle of addiction and despair,” Cullen said in a statement.

More than 300,000 people have died in the opioid overdose crisis since 2000.

Smithers, 36, a married father of five from Greensboro, North Carolina, testified that he was a caring doctor who was deceived by some of his patients.

Some patients remained fiercely loyal to him, testifying that they needed the powerful opioids he prescribed for them to cope with chronic pain.

Prosecutors said many patients would drive hundreds of miles one-way to get to Smithers’ clinic in Martinsville.

Smithers prescribed opioids to every patient in his practice, according to prosecutors. Before a warrant was served on his clinic, he took in more than $700,000 in cash and credit card payments. He did not accept insurance.

WSET-TV reported that the judge recommended that Smithers serve his sentence in a prison close to his family and that he receive mental health treatment.

Smithers wrote in a court filing that he plans to appeal his convictions. His attorney did not immediately respond to an email seeking comment on the sentence.