This story was published in partnership with The Marshall Project.

Kayla Duggan, a heroin addict, had just started a one-year jail sentence in Massachusetts when she was startled to learn she was pregnant. Only a few months earlier she had given birth to a baby girl who was immediately taken into foster care and whom Duggan then gave up for adoption.

This time she wanted to be part of her child’s life.

Her chance came about because of a policy change in Massachusetts in which women addicts, particularly mothers, are increasingly directed to intensive drug treatment and away from time behind bars.

Duggan, who was imprisoned in late 2012 for a domestic violence and drug-related conviction, was paroled after serving four months of her sentence and entered a residential drug-treatment program for mothers run by Spectrum Health Systems. Spectrum, a private company that works with the Department of Correction, also has smaller outpatient clinics across the state. Duggan gave birth to her son, Giovanni, while living there, still under correction department custody, and remained until he was six-months-old. Afterward she moved into a Boston halfway house.

“I got a beautiful second chance to be a mother to my son,” said Duggan, now 26. “I had to learn to be responsible, be available today. Because I wasn’t available before.”

Because of the opioid drug crisis sweeping New England, women have become the fastest-growing group heading to jail or prison, a situation reflected nationwide. This cohort includes young mothers—usually the primary caretakers to young children—and the long-term effects on kids and families can be devastating.

Mothers, separated physically from their children while in prison, can come to experience emotional separation as well, said Judy McDonough, executive director of Edwina Martin House, a residential treatment center for women outside of Boston. A growing number of its clients are referred by the courts and probation officers.

Meredith Derby Berg

“And then they start to lose their confidence in who they were as a parent and feel their kids are better off maybe with their parents. So it really fragments the family,” McDonough said.

A panel convened this year by Republican Gov. Charlie Baker of Massachusetts concluded that mothers and pregnant women need “specialized care.” Its report recommended that treatment centers make pregnant women a priority. In 2014, the state funded two new recovery homes specifically for women, bringing the state’s total to 14.

Those who work in the field say there’s a growing recognition within the Massachusetts criminal justice system and among policymakers that intensive drug treatment can be a key to helping women transform their lives in a way that prison does not.

“The courts were not so involved with treatment as they were with, let’s say, punishment in a sense. And thankfully that’s turned around,” said Donna McDade, McDonough’s colleague at the Edwina Martin House, where she has served as director for 24 years.

Massachusetts is among a number of states working to address the needs of addicted mothers who are facing criminal charges. A 2010 report by the National Women’s Law Center said that 32 states had programs that offered mothers who are nonviolent offenders the possibility of what is called “family-based” treatment rather than prison or jail time. Family-based treatment permits mothers to live with their children at a site within the community or visit them regularly there while receiving drug abuse treatment.

Kent Hernandez/FUSION

But keeping such alternatives funded can be challenging, said Edward Latessa, director of the School of Criminal Justice at the University of Cincinnati. He said that despite the rise in the number of incarcerated women, they still constitute only 8% of the national prison population.

“As a general rule there tend to be fewer [alternative sentencing] programs for women, but it really varies by state and jurisdiction,” he said. “Of course many female offenders have substance abuse problems and are in need of treatment and recovery programs, but again, for service providers, since the numbers are smaller it is not always economically feasible to open a facility for women. In addition, if you are including mothers with young children the costs go higher, which again makes it more difficult to operate.”

The federal Bureau of Prisons has its own long-standing program called Mother and Infant Nurturing Together, or MINT. It allows pregnant women in minimum security prisons, among them drug addicts, to reside in halfway houses before they deliver and after they give birth for up to 18 months. These women, who are eligible for release within five years, are taught parenting skills with the goal of encouraging bonding with their babies and are also eligible to be treated for addiction.

For both men and women addicts charged with crimes, the doubling of the number of drug courts nationally in the last decade, to 2,966, has increased opportunities for defendants to serve at least part of their time at residential treatment facilities or halfway houses instead of prison or jail.

“You cannot just lock people up and incarcerate them and expect their substance abuse issues to go away.”

But diversion or treatment programs have not found universal acceptance. In Tennessee, South Carolina and Alabama, women are being prosecuted and locked up for endangering their children by using drugs when pregnant. Eighteen states have laws stating substance abuse during pregnancy is child abuse.

The evolution of Massachusetts’ approach has been aided by the jump in the number of drug courts established in the last two years, adding five new ones for a total of 18.

Drug courts are vitally important now because it’s where the state can refer people to residential drug treatment homes instead of jail or prison. And even though more women are being arrested and convicted, fewer female defendants are actually being sent to serve time. According to the Massachusetts Sentencing Commission, there was a 4% drop, to 1,625, in the number of women incarcerated from 2012 to 2013.

In previous years a woman who was addicted to drugs and charged with a non-violent crime could be given the choice between jail and a residential drug treatment center, but the numbers of court-ordered referrals now appear to be rising dramatically. It’s now more likely that residential treatment will become part of an offender’s sentence. The average number of probationers at 12 women’s-specific recovery homes in Massachusetts rose to 60 percent in 2014, from 25% in 2009, according to annual enrollment reports from the Massachusetts Bureau of Substance Abuse Services.

In 2014, the opioid crisis led to a record 1,000 fatal overdoses. The state has tested a range of responses, from trying to ban the powerful painkiller Zohydro to offering prostitutes mental health or medical treatment instead of jail. One city, Gloucester, created an amnesty program for addicts.

The state does not track the number of people who are offered—or manage to win—an alternative to incarceration. But judges say they are becoming more aware of the harm incarceration can have on families and that addiction may not be adequately addressed in jail. Longtime program directors report that they now get more referrals from judges than they once did.

“Many of us, and I am one of them, firmly believe that you cannot just lock people up and incarcerate them and expect their substance abuse issues to go away. It’s just not working anymore,” said District Court Justice Mary Heffernan, who runs two drug courts. “You have to put the resources into treatment.”

Beyond residential centers, treatment options include intensive outpatient addiction programs that require daily, daylong attendance. These programs can mandate community service combined with substance abuse counseling, job training, electronic monitoring, and drug testing.

Vincent Lorenti, regional program manager of the Massachusetts Office of Community Corrections, described his department’s program as “halfway between traditional probation and incarceration.” Annual community corrections statistics show that women make up an increasing percentage of the program, up 5% between 2011 and 2014.

At residential recovery homes such as Edwina Martin House, which receives significant state funding, the average four-to-six month stay costs $12,000 to $18,000. At the women’s prison in Framingham, the oldest women’s prison in the country, six months costs $30,000 to house an inmate, according to corrections department data.

Part of the rehabilitation process is helping women to relearn basic life skills that atrophied as they began their descent into addiction. These include structuring their days, keeping appointments, shopping for groceries and cooking. Group and individual therapy sessions emphasize self-esteem. They also work to rebuild connections with their families and children. At some homes mothers live with their infants and pregnant women await delivery.

Meredith Derby Berg

About 6:45 each morning the ringing of alarm clocks echoes through the corridors of the Edwina Martin House. The women shower, make their beds and tidy their bedrooms. By 9 a.m. they are attending group meetings on topics like music expression, relapse prevention, household budgeting and family dynamics. Some women go to work, others go to vocational training or take classes. In the evenings they attend Alcoholics Anonymous or Narcotics Anonymous meetings.

Though jail time can include access to substance abuse programming, it’s not considered to be as intensive. “Jail doesn’t fix the issue of addiction. You’re there, and it’s just time. You’re idle,” said Stephanie, who asked to be identified by her first name only. She is a mother who was ordered by a drug court to attend Project Cope, a Boston area women’s recovery home.

It’s not an easy road, and treatment is no panacea. At Edwina Martin there is a 48% program completion rate, but that is still better than the state average of 31% completion, according to McDade.

The clients Edwina Martin has seen in recent years are young, usually in their early 20s. Typically they did not experiment much with other drugs before becoming hooked on opioids. “We have great success with them, because they are young,” says McDade. “They have not had as many losses. But their losses come quick with heroin.”

Duggan relapsed several months after leaving the Boston halfway house and lost custody of her son. In November she won him back from state custody.

This story was written by Meredith Derby Berg for The Marshall Project, a nonprofit news organization that covers the U.S. criminal justice system. Sign up for their newsletter, or follow The Marshall Project on Facebook or Twitter.