The Texas State Supreme Court on Thursday ruled that the removal of children from a polygamist religious group’s ranch by child welfare authorities was unwarranted and that the children should be returned.

The court’s ruling upheld a decision issued last week by the Third Court of Appeals in Austin finding that a state district court judge had not been justified in allowing the Texas Department of Family and Protective Services to remove hundreds children from a ranch complex near Eldorado in April.

In Thursday’s decision, the Supreme Court noted that while “the district court must vacate the current temporary custody orders as directed by the court of appeals,” the district court judge could impose conditions to protect the children including preventing their removal from beyond a geographical area.

Although the Supreme Court on Thursday instructed the district court to vacate its original order approving the children’s removal, it did not set a timetable under which they should be returned. Thursday’s decision involved 126 of the children, but a lawyer for representing one of the children seized from the ranch has said previously that the decision would effectively apply to all of the children taken into state custody.The Supreme Court said state child welfare officials must meet several legal standards concerning the safety of the children in order to justify removal  such as proving that state officials made a reasonable effort to enable the children to return home but that there was a substantial risk of continuing danger if the children were returned.