Thousands of people staged protests across Poland on Thursday after President Andrzej Duda signed into law a measure effectively letting the government choose the next Supreme Court chief.

The European Union, human rights groups and opposition parties in Poland say the legislation and other changes pushed by the ruling Law and Justice (PiS) party undermine judicial independence and democracy.

Crowds gathered outside the presidential palace in Warsaw chanting “shame.” Many held candles and pens, referring to Duda’s readiness to sign. They shouted, “Break the pen” and “You will go to prison.”

Similar protests took place in more than two dozen cities and towns across Poland.

The PiS party says an overhaul is needed to make the courts more efficient and eradicate the influence of Poland’s communist past.

“Without [judiciary] reforms, we cannot rebuild the Polish state so that it serves its citizens,” said Jaroslaw Kaczynski, leader of the euroskeptic party which combines left-leaning economics with nationalist politics.

Earlier this month, 22 Supreme Court judges were forced into early retirement but chief judge Malgorzata Gersdorf has refused to go, saying her constitutional term does not expire until 2020.

The latest amendment, which was adopted by the upper house of parliament earlier this week, is designed to make it easier to name the new Supreme Court head.

Since PiS won power in 2015, dozens of judges have been effectively dismissed from the Constitutional Tribunal, the National Judiciary Council, which decides judicial appointments, and now the Supreme Court.

New appointments have used procedures that give parliament, where the PiS has a majority, greater say over the courts and the government more control over judges.

The European Commission is running an unprecedented rule of law investigation and has opened several separate legal cases against Poland, the largest former communist EU state, including some over the Supreme Court.