A new study concludes the Affordable Care Act could give an estimated 4 million people who have spent time in U.S. jails better access to health care, including coverage for treating substance abuse and mental illness.

While the law does not change health care access for people while they are in jail, it does improve the chance they will receive health coverage before and after they are in jail. This could reduce the chance they will end up being reincarcerated, the researchers said.

“Enrolling people who are to be released from jail will require substantial effort and resources,” study co-author Sara Rosenbaum of the George Washington University School of Public Health and Health Services said in a news release. “However, this investment will pay off in terms of better health, reduced costs and possibly the reduced risk of additional jail time.”

Many people in the nation’s 3,200 jails are mentally ill or homeless, HealthDay reports. Unlike people in prison, those who are in jail typically are arrested for misdemeanors or nonviolent crimes. About two-thirds of people sent to jail meet the criteria for mental illness at the time of their arrest, and about the same number have problems with alcohol or drug abuse, the researchers said. People in jail are often quickly released, but if they do not have access to health care, they are more likely to be rearrested.

Under the Affordable Care Act, people who have served time may be eligible for Medicaid coverage after they are released from jail. They also may benefit from new Medicaid expansion programs designed to provide coverage for more low-income Americans.

The study, published in Health Affairs, estimated that one in six people who are expected to enroll in Medicaid in states that have opted to expand their Medicaid programs will have spent time in jail in the past year. The researchers also estimated that one in 10 people enrolling in health plans through new online insurance marketplaces will have recently spent time in jail.