A former Arkansas judge who dismissed cases for “community service” where he took pictures of boys and young men masturbating and as he spanked them has been sentenced to five years in federal prison.

O. Joseph Boeckmann, 71, of Wynne, Ark., was sentenced after admitting in a plea agreement to the seven-year-long fraud and bribery scheme where he dismissed cases in exchange for personal benefits, the Department of Justice said in a release on Wednesday. Boeckmann admitted to dismissing traffic citations and misdemeanor criminal charges from 2009 to 2015 for young men and boys in exchange for acts that he claimed were community service, but actually benefited himself.

A grand jury indictment included nine cases of boys and men between 16 and 22 where Boeckmann privately gave his phone number to defendants in his court to arrange community service outside of the court system. Some labored at his house, but others were photographed naked, while masturbating or while Boeckmann spanked their bare bottoms.

“He dangled their case dismissals in front of them while making them do his bidding,” a sentencing memorandum states. “He posed them in embarrassing positions; positions that he found sexually gratifying. And when he sensed an opportunity to ask for more, he would take it — using the men’s powerlessness and poor socioeconomic circumstances to create a personal collection of explicit, exploitative images.”

Investigators found that Boeckmann had 46 printouts of 16 young men stashed under his bed.

The indictment and memorandum were published online by the American Bar Association Journal.

Boeckmann was investigated by the FBI for similar conduct in the 1990s, when he was a part-time deputy prosecuting attorney, the memorandum states. He wasn’t charged because he agreed to resign, but he was elected as a district court judge a few years later.

He pleaded guilty to wire fraud and was fined $50,000 for the fines and other money that various Arkansas cities and counties should have received from the dismissed cases. Boeckmann dismissed 66 cases involving white or Hispanic boys and men between 15 and 35 for community service in 2014 alone.

Boeckmann also pleaded guilty to bribing a witness in an attempt to obstruct an investigation into his scheme.

He resigned as a district court judge for the First Judicial Circuit of Arkansas in May 2016.