Nearly 20 years after voters legalized medical marijuana, California lawmakers have finally passed legislation to regulate the growth and distribution of cannabis for patients' use. In the final hours of their session last week, legislators passed three bills that together establish a system to license, test and track medical marijuana from "seed to sale." Gov. Jerry Brown, who helped craft the deal, should not only sign the bills into law, but he should stay focused on ensuring their smooth, effective implementation.

California was the first state to allow medical marijuana, but the Compassionate Use Act of 1996 provided little guidance on how the state could help ailing patients get the drug — or how to keep it out of the hands of those who weren't entitled to it. Legislators repeatedly failed to develop rules, so cities and counties adopted a patchwork of policies, which triggered a series of lawsuits and judgments that created a confusing mess for patients, law enforcement, cannabis growers and dispensary operators.

These bills are an attempt to turn that chaotic quasi-legal, supposedly nonprofit system into a transparent, legitimate commercial industry. Anyone working in the cannabis business would need to be licensed, and the state would regulate each step in the growth and distribution chain. The Department of Food and Agriculture would oversee indoor and outdoor marijuana cultivation. The Department of Public Health would set rules for marijuana processing and testing by third-party laboratories to ensure products are checked for quality and safety, as well as packaged and clearly labeled as cannabis. A newly created Bureau of Medical Marijuana Regulation would regulate the transportation, distribution and sale of pot.

Critics complain that the bills are incomplete and were rushed to a vote at the 11th hour. That's probably true, but the bills merely create the framework for how California will regulate medical marijuana; state agencies still have to work out the details and develop specific rules before the licenses are required in 2018. It's also true that marijuana is still illegal under federal law and that California's proposed regulatory system could be moot in a couple of years if the next president cracks down on states that have legalized medical and recreational use. But lawmakers cannot continue to ignore the state's booming medical marijuana industry, nor the possibility that voters will get a ballot measure in 2016 to legalize recreational use. Sign the bills, governor, and let's get started on the hard work of cleaning up the state's marijuana mess.