A court in Kenya has ruled that the use of forced anal examinations on men suspected to be gay is unlawful.

An appeals court in Mombasa made the ruling Thursday, saying another court decision that had upheld the practice was unconstitutional and a violation of human rights, the Associated Press reports. The ruling came in the case of two men who were arrested in 2015 under Kenya’s law against same-sex relations. then forced to undergo anal exams and HIV testing to determine if they had engaged in consensual sex.

The exams are so painful and humiliating that they constitute torture, and they are of no medical value, according to human rights activists, who praised the appeals court’s decision.

“We are thankful that the Appeal Court has put Kenyan citizens’ rights first,” said Njeri Gateru, head of legal affairs at Kenya’s National Gay and Lesbian Human Rights Commission, in a press release. “With this ruling, the judges are saying that we all deserve to be treated with dignity and afforded our basic rights, as enshrined in the Kenyan Constitution. The humiliation and pain caused by these useless anal examinations will follow our clients for the rest of their lives. However, we are emboldened to see our constitution at work, ensuring that all Kenyans have the right to dignity.”

Jessica Stern, executive director of OutRight Action International, also issued a statement on the ruling. “Forced anal examinations amount to torture, and no one should ever be exposed to such a degrading and dehumanizing experience,” she said. “The Kenyan courts ruled in favor of international law and in favor of human dignity. Other countries should follow suit and put an end to this discredited practice.” Countries still engaging in the practice include Egypt and Tanzania, according to OutRight.

Under Kenya’s penal code, same-sex relations are punishable by up to 14 years in prison. The nation’s High Court is scheduled to hear a case challenging the law April 26.