Ronald Reagan emptied the psychiatric hospitals and Jerry Brown emptied the prisons, or so some people say. Although neither statement is completely true, there are elements of harsh reality in both. And they are connected.

Reagan and Brown, two of the most consequential governors ever in California, led the state during two of the most well intended but poorly executed movements in this state’s history.

The first was the de-institutionalization of the mentally ill starting in the 1960’s. The movement, started in Europe, was supported by President Kennedy and ultimately complicated by a U.S. Supreme Court opinion and civil liberty concerns over forced treatment.

The second in recent years was fueled by concerns about perceived mass incarceration, and the reality that our jails and prisons had become the de facto mental facilities.

The result: fewer inmates, and significant increases in homelessness and untreated mental illness.

I have witnessed this as a county prosecutor, deputy attorney general and El Dorado County District Attorney. As someone with more than 27 years in the pursuit of justice, I worry for the people on the streets, and for the future victims of crime.

The history of psychiatric treatment isn’t pretty. Too many people who were institutionalized for mental disorders suffered abuse, neglect and mistreatment. Gov. Reagan signed the Lanterman-Petris-Short Act in 1967, all but ending the practice of institutionalizing patients against their will.

When deinstitutionalization began 50 years ago, California mistakenly relied on community treatment facilities, which were never built. And the Lanterman-Petris-Short Act made it virtually impossible to compel treatment prior to extreme decompensation.

The consequence became clear quickly. The number of mentally ill people entering the criminal justice system doubled the first year after the Lanterman-Petris-Short Act was enacted.

We in the criminal justice system use the expression “life on the installment plan” to describe the cycle.

Offenders would commit low level crimes and be incarcerated. Jail or prison for many meant stabilization through regular sleep, food, hopefully no alcohol or drugs, and for some, much needed mental health treatment. Then, they’d be released.

Back on the streets, they would decompensate, get arrested again and continue to serve life on the installment plan.

The connection between deinstitutionalization and incarceration is all too obvious. In 1978, the prison population was about 25,000, By 2006, it had grown to over 170,000 and 30 percent of the prison population were designated as needing mental health services.

In the last several years, California engaged in mental health deinstitutionalization 2.0. This time it was Gov. Brown who pushed for sweeping new laws.

Measures approved by the Legislature and voters have drastically changed the legal landscape and reduced prison and jail populations. By the end of his tenure, prison population has fallen by almost a third.

As the jails and prisons emptied, homelessness jumped. Unlike the rest of the U.S. where homelessness has been relatively flat, California’s homelessness spiked in 2015. Now, approximately a quarter of all people experiencing homelessness in this country reside in California.

And while there are fewer inmates, the prevalence and severity of the mental illness among prisoners has increased. Astonishingly, in just four years, the number of people in California who were deemed incompetent to stand trial has increased by 60 percent, straining courts and state hospitals.

Somehow, we must find a middle ground between incarceration, and untreated, unsupervised and at-risk mentally ill people.

Senate Bill 1045 became law Jan. 1, and authorizes pilot programs to create housing conservatorships for people with serious mental health illness and substance use disorders who do not qualify for Lanterman-Petris-Short Act conservatorship in Los Angeles, San Diego and San Francisco.

This is a modest step, but it could help insure treatment for people with mental disorders outside the criminal justice system. Community based treatment before extreme decompensation, such as has worked in Europe, could greatly reduce incarceration and homelessness.

Ultimately, isn’t it time to reevaluate our legal perspective that essentially determined that the mind was like a light switch, where a person is either perfectly sane or an immediate threat to him- or herself and others?

Vern Pierson is El Dorado County District Attorney, and a board member of the California District Attorneys Association, vern.pierson@edcgov.us. He wrote this commentary for CALmatters, a public interest journalism venture committed to explaining how California’s Capitol works and why it matters.