BY THE TIME someone gets to jail, in many cases, there are myriad societal problems that led them there – and those need to be addressed.

That was the premise voiced by US Sen. Ed Markey and his challenger in the Democratic primary for Senate, US Rep. Joe Kennedy, in back-to-back question and answer sessions with inmates inside the Suffolk County House of Correction on Tuesday.

Whether the problem is a lack of mental health care or lack of affordable housing, Markey and Kennedy both pledged to address systemic problems that result in a churning criminal justice system where Massachusetts inmates who are released from state prison have a 33 percent chance of returning within three years.

Markey said you can learn a lot about a country by who it jails, whether journalists or political enemies. “We imprison the poor, those who have substance abuse problems,” Markey said. “We imprison the black and brown citizens in our country in disproportionate numbers and we don’t provide resources to make sure they get the help before they get into trouble, while they’re in prison, and after they leave prison.”

The event was held as protests against racism and police brutality are roiling the country over the killing of George Floyd, an unarmed black man, by a white police officer. Inmates at the Boston correctional facility asked each of the candidates about holding the police accountable for misconduct.

“We shouldn’t live in fear every day when in prison of [correction officers] or on the street that we’re going to be stopped for no reason, then the second they run our names, we’re messed with,” one woman told Kennedy during the session, which was streamed live on Facebook.

Kennedy touted legislation to make it easier under federal law to hold the police accountable and to create a national database for police complaints so officers cannot move between departments.

Markey reiterated calls to abolish qualified immunity, a doctrine that makes police officers immune from civil liability for actions on the job, and to require police officers to wear body cameras. Markey said he supports abolishing the use of tear gas, abolishing chokeholds, and not allowing the federal government to sell military-grade equipment to local police.

Markey did not use the word “defund” the police, but said there needs to be a “reallocation of resources” to pay for social workers, employment opportunities, mental health services, and drug rehabilitation facilities. “We have to reallocate budgets to make sure funding is there for all the programs that in the end will avoid the school to prison pipeline,” Markey said.

Both Markey and Kennedy said the state must do a better job addressing mental health and substance use problems.

Markey traced the issue back to deinstitutionalization 35 years ago, when the US phased out the practice of confining mentally ill people in institutions – but failed to provide enough funding to treat people in the community. “What we have to do is make sure we provide treatment access for all those people before they do something that results in the police taking them,” Markey said.

Kennedy said one lesson he learned from his time as a prosecutor is the inadequacy of the justice system in dealing with people struggling with addiction or mental illness. For example, he said if a homeless person bothers customers at McDonald’s, the response has been to charge them $100 for trespassing rather than offer behavioral health services.

Kennedy recalled one instance when the parents of a boy who stole family jewelry to pay for oxycodone called the police then begged Kennedy to get him held without bail. The parents said they found a treatment bed for their son, a combat veteran, the following Monday but feared what would happen if he remained free over the weekend. The veteran apologized to the judge and his family and said he wanted help – but added, Kennedy said, “If you release me, I don’t know what I’ll do.”

Several offenders asked both candidates how they would help them provide for their families without returning to trouble, noting struggles to obtain housing, childcare, and transportation. Both Markey and Kennedy stressed the importance of funding these areas and other initiatives to lower the barriers to reentry, such as making it easier for a former prisoner to obtain a professional license.

Markey touted legislation he sponsored to give government grants for local initiatives that make part of their public transit systems fare-free.

Kennedy noted that in Massachusetts, the cost of childcare exceeds the cost of tuition at the University of Massachusetts. “How can you possibly make that…feasible for a lower income family to make ends meet? There’s no way,” Kennedy said.

Kennedy also acknowledged the need for more services to keep 18-year-olds who age out of the Department of Children and Families out of the criminal justice system. “An 18-year-old to me is still a kid,” Kennedy said. “Now to say you’re on your own? No family that has the ability would ever wish that on an 18-year-old.”

The event was moderated by Suffolk County Sheriff Steven Tompkins, who has endorsed Kennedy. Tompkins, who did not mention his support for Kennedy during the event, took time during both candidates’ appearances to make his own policy appeals.

“It’s asininely stupid if you have a felony you can’t vote when you get out. What happened to us being a nation of second chances?” Tompkins said during Markey’s appearance.

During Kennedy’s time, Tompkins opined on people saying jails need less money if they house fewer inmates. “I say bullshit,” Tompkins said. “The quality of care that’s needed costs more.”