If 3-year-old James understood what was about to happen to him, he didn't show it. He was focused on the vending machine in the lobby of the Hennepin Juvenile Justice Center.

His foster mother, Erin Meier, picked him up off the floor. "No, we're not doing candy," she said. What Erin and her wife, Pernell, were doing in court that day was this: ending three years of struggle with Hennepin County over their efforts to adopt him.

From the day he was born, James has been severely neglected, once left near a hypodermic needle in a drug den and twice gone missing. His case caused Hennepin County Attorney Mike Freeman to vow that his office would change how they handle child protection cases.

The Meiers fostered James after he was born addicted to drugs. After the couple gave him back to his mother, they pleaded in vain with child protection to check on the boy. James went missing for a time, and when he was found, the county asked the Meiers to step in again as foster parents. Still, the Meiers said they have received frequent threats from the county that James could be taken away from them again.

"Today is the day we know that won't happen," Pernell Meier said.

The Meiers got a call from a social worker on May 9, 2013, a day after James was born in a basement with opiates and cocaine in his blood.

The Meiers thought they were done with being foster parents.

They had four children they had fostered and adopted at their southern Minnesota home and didn't think they could handle another. But James was different. One of the Meiers' adopted children, Justin, was James' half-brother.

They agreed, hoping they might be able to adopt him.

The boy's mother, Cynthia Kiewatt, has a history of drug abuse, prostitution and maltreatment of her children dating to 2001, leading to the involuntary termination of her parental rights to two older children, court records show.

Under state law, that would have allowed the county to ask a judge to terminate Kiewatt's parental rights to James.

But Kiewatt made such good progress in treatment that the county reunited her and James in September 2013. In February 2014, a judge closed the case.

The Meiers continued to worry about the boy. In December 2014, they found online prostitution advertisements for Kiewatt.

The Meiers sent the ads to Hennepin child protection workers, hoping they would come to the boy's aid. But in February 2015 the county told the Meiers that there would be no investigation.

Two weeks later, the county got a new report about Kiewatt, prompting child protection to reach out to her. But she and James went missing. Kiewatt dropped out of sight until Sept. 16, 2015.

That morning, a clerk at the Northwood Inn in Bloomington told police about a guest who appeared to be high and had a young boy with her, according to police records. Officers found James lying on a bed in a room strewn with cocaine, meth, crack pipes and dirty needles, according to court reports.

Officers gave the boy to a friend of Kiewatt, believing he'd be safe, but he went missing again. After the situation was reported in the Star Tribune, police found him the next day with his father, James Salter, who was arrested.

The Meiers said the county reluctantly asked them to foster James. They hoped to adopt him, but the county told a judge they would allow his mother to try again to reunite with him.

When the Star Tribune reported the county's intention, Freeman reversed course. As a result of the case, Freeman said his office would be more aggressive in terminating the rights of parents who repeatedly abuse their children.

Since then, Freeman said last week that "child protection has become much more aggressive, conducting their investigations quicker and more thoroughly."

That likely has contributed to a quadrupling in the number of Hennepin County children being put up for adoption since 2009. Currently, 339 children in the county are awaiting adoptive families.

Over the New Year's holiday, painful boils on James' skin prompted the Meiers to take him to an emergency room.

He was diagnosed with MRSA, a bacteria that can be deadly if not treated. The Meiers remember holding James down as he screamed in pain while a nurse tried to find a vein for an IV.

In February, a judge terminated the parental rights of Kiewatt and Salter.

Kiewatt has not seen James since. Salter was shot and killed in July in an alleged robbery attempt.

Despite all that James has been through, the Meiers said it's been a joy to have him.

"I'm quite stunned at how well he's doing," Pernell Meier said. "He seems very content and just generally happy."

When their case is called on Nov. 10, the Meiers walk into the courtroom with their four kids. Judge Luis Bartolomei's approval of the adoption is a formality, but the Meiers are still nervous.

Bartolomei tells 6-year-old Justin that at the end of the hearing, he'll need the boy's help. Then he turns to the Meiers.

"Do you freely accept the obligation," Bartolomei asks both parents, "to provide James with love, with security, with a home and with the necessities of life and the best available education?"

"Yes," they say. "Absolutely."

The judge pauses and talks slowly, bringing one last moment of panic to Pernell. But Bartolomei is waiting for Justin. He waves him up to the bench.

"If this is going to be official, you need to bang the gavel twice," he tells him.

There's a count of three, two, one. Justin bangs the gavel. Sitting on his adoptive mother's lap, James claps.

Staff writer Kelly Smith contributed to this report.

Brandon Stahl • 612-673-4626