The Iowa Supreme Court has upheld the conviction of a former high school teacher who argued that his hugs with a 17-year-old student didn't amount to sexual misconduct.

The justices wrote in their ruling Friday that although nothing should prohibit teachers from hugging students for reassurance, comfort, or in congratulation, the hugs that 38-year-old former Camanche High School teacher Bradley Wickes gave the student had a more nefarious intent.

The court said that in thousands of Facebook Messenger exchanges between Wickes and the student during a 45-day period, it was clear that she had "become the object of Wickes's fantasies and sexual desires, and the hugs that coincided with these messages were for his sexual gratification."

Wickes was convicted in 2015 of a charge of sexual exploitation by a school employee and sentenced to five years in prison.