Pennsylvania’s Supreme Court ruled last month that young people may no longer be held in adult prisons while awaiting juvenile court hearings.

The high court ruling redefines “detention facilities” to expressly exclude state- or county-level jails or prisons, while similarly altering the state’s definition of “juvenile” to include youths who have been placed in detention for probation violations.

Under Pennsylvania law, all minors ages 10 to 17 must have their cases heard in juvenile court. In some instances, youth as old as 21 may remain under the jurisdiction of the juvenile court.

“Every once in a while a judge would find someone who is under juvenile court jurisdiction, but over age 18, and want to teach them a lesson and put them in county jail,” Robert Schwartz of Philadelphia’s Juvenile Law Center told The Scranton Times-Tribune.

“Now, as long as you are under juvenile court jurisdiction, you are not allowed to be put in an adult facility,” he added.

Members of Pennsylvania’s Juvenile Court Procedural Rules Committee proposed the changes that learning that on several occasions juveniles in the state had been placed in adult facilities while awaiting juvenile court appearances.

The new ruling, however, does not prevent Pennsylvanian juveniles from being held in state or country jails if they have been charged as adults. It also does not prevent the jailing of those 18 or older if they fail to appear at one of their juvenile court hearings.

“It’s an excellent change that reflects the true purpose and intention of the juvenile justice act — to rehabilitate children who are deemed to be in need,” Larry Moran, a Lackawanna County chief public defender, told The Scranton Times-Tribune. “It does not make sense that kids should be locked up in institution that punishes adults charged with crimes.”