More than 50 children under age 5 who were taken from their parents at the U.S.-Mexico border are expected to be reunited with them Tuesday, lawyers for the federal government told a judge in San Diego on Monday.

About 40 other very young children will not be returned to their parents yet, despite a court-imposed deadline, because the Trump administration either has not finished matching them with their parents or has not cleared the parents to take custody. Two children have already been reunited with their parents, lawyers said.

U.S. District Judge Dana M. Sabraw — who last month called the family separation process “chaotic” and set a timetable for the government to reunite the families — said Monday he was pleased that the Justice Department and the American Civil Liberties Union worked together through the weekend to facilitate the return of the children to their parents.

“I am very encouraged about the progress,” Sabraw said during a hearing in U.S. District Court in San Diego. “This is real progress. I’m optimistic that many of these families will be reunited tomorrow.”

He scheduled another hearing for Tuesday morning to get further updates on the reunifications, which he ordered as part of a class-action lawsuit filed by the ACLU. They come amid a tide of national and international outrage over such young children being taken from their parents.

Sabraw had ordered the government to return all children age 4 and younger to their parents by Tuesday. Federal agencies have until July 26 to return children 5 and older who are among the “under 3,000” taken from their parents. The government separated the families as part of the Trump administration’s effort to criminally prosecute all immigrants who cross the U.S.-Mexico border illegally, including those who are seeking asylum.

Justice Department attorney Sarah Fabian said the reunifications Tuesday will occur in undisclosed locations administered by U.S. Immigration and Customs Enforcement, which has custody of the detained parents. Their children have been kept in federally run shelters and in foster homes.

“The kids are all over the country,” ACLU lawyer Lee Gelernt said. “It may end up being different for the older kids. But for these kids, it’s going to be all over the country.”

The reunited families will then be released and allowed to stay in the United States pending further immigration proceedings — the exact opposite of what President Trump and Attorney General Jeff Sessions had hoped to accomplish when they launched the “zero tolerance” effort in May.

“ICE will take custody and then release the parent and child together,” Fabian said at Monday’s hearing. “They will not remain in ICE custody.”

Also Monday, a federal judge in California sharply rebuked the Justice Department for seeking a modification to a long-standing court settlement. The Trump administration had asked for the court’s permission to have ICE keep those families in detention until their cases were adjudicated — a process that typically takes months and would have gone against previously established terms of the settlement.

Justice Department lawyers had filed an application to U.S. District Judge Dolly M. Gee more than a week ago seeking her approval to detain parents and their children together for unspecified periods of time.

In a seven-page order, the judge called that request “a cynical attempt, on an ex parte basis, to shift responsibility to the judiciary for over 20 years of congressional inaction and ill-considered executive action that have led to the current stalemate.”

She noted that the issues at stake had been part of the Flores settlement — which deals with how the government can keep children in custody — for more than two decades.

“What is certain is that the children who are the beneficiaries of the Flores agreement’s protections and who are now in [the government’s] custody are blameless. They are subject to the decisions made by adults over whom they have no control,” Gee wrote, saying that she rejected the government’s request “because it is procedurally improper and wholly without merit.”

Justice Department spokesman Devin O’Malley said the administration has made good-faith efforts to address the issue and disagreed with the judge’s ruling.

“The court does appear to acknowledge that parents who cross the border will not be released and must choose between remaining in family custody with their children pending immigration proceedings or requesting separation from their children so the child may be placed with a sponsor,” O’Malley said.

Trump’s family-separation policy ignited an outcry from Pope Francis and the United Nations High Commissioner for Refugees, among others. A Honduran man hanged himself after his son was taken from him. On Monday, advocates for immigrants said there has been an outpouring of support nationwide for the soon-to-be reunited families, including offers of places to stay and money to resettle in the United States as they await deportation hearings.

“We are seeing that people are opening up their homes,” said Heidi Altman, director of policy for the National Immigrant Justice Center.

Lyft said it will provide free rides to nonprofit groups helping to reunite families in Texas, Arizona and other states.

Government lawyers said some reunions may not immediately be possible because parents have not been located or are still serving criminal sentences, such as for crossing the border illegally. Others are still going through the backgrounding process to ensure they are the children’s parents and fit to take custody of them.

The Justice Department has asked for more time to reunite parents — or to be excused from reuniting those who are deemed unfit — but Sabraw did not rule on that request Monday.

Instead, he ordered both sides to provide a status report Monday night on the reunification procedures, and an update on numbers Tuesday morning.

The hearing Monday focused primarily on the status of the youngest children and did not include details on whether the government would be able to meet the deadline for reuniting the older children with their parents later this month.

The ACLU and others have blasted the Trump administration for shoddy record-keeping after they separated the families, saying the government apparently had no plan to eventually bring them back together. Federal officials have said somewhere “under 3,000” migrant children have been separated overall, but their numbers have varied.

On Friday, Fabian told the judge 101 children were under 5. On Monday, she said there were 102 children in that age group, and that two had already been returned to their parents.

Also Friday, Fabian said 19 parents were deported and 19 were released. But on Monday, she said nine were removed from the United States and an additional nine were released here.

Justice Department spokeswoman Sarah Isgur Flores had no comment on the discrepancies in the numbers.

To speed the reunions and reduce confusion, Sabraw had ordered the government to provide a list of the separated children’s names to the ACLU over the weekend.

Gelernt, the ACLU lawyer, said in court that the government had taken “significant steps” to reunite families but should be moving more quickly.

“I believe that they can still reunite some [more] individuals by tomorrow,” Gelernt said during the hearing. “We just don’t know how much effort the government’s made to find” the parents.

Sacchetti reported from Washington and Perry reported from San Diego. Devlin Barrett in Washington contributed to this report.