Almost 20 years after voters approved Proposition 215, California lawmakers passed a sweeping set of measures late Friday night designed to finally put some order into the crazy patchwork of policies governing the medicinal use of marijuana.

A few weeks before the 1996 election, Sen. Diane Feinstein said the Compassionate Use Act was so poorly written, “You'll be able to drive a truckload of marijuana through the holes in it. While its seems simple, the devil is in the details or, in this particular bill, the lack of details.” Friday’s vote hopes to infuse some clarity into those details. “We’re making up for two decades of inaction,” said Mike McGuire, a State Senator who represents the northern California district where 60% of the marijuana grown in the U.S. is cultivated. He authored S.B 643, the Medical Marijuana Regulation and Safety Act, one of the measures passed Friday. “After two decades of no regulation, I am pleased to report an agreement has been reached on one of the most comprehensive medical marijuana bills in the nation…these regulations are long overdue and I’m thrilled that we were able to work together to find common ground on historic medical marijuana regulations for our state.”

Under the trio of bills passed Friday, a new Bureau of Medical Marijuana Regulation will be created within the existing Department of Consumer Affairs. This new bureau will be in charge of regulating almost all aspects of marijuana growing, distribution and sale. It will regulate state licenses, but only if a local license has already been approved. Lawmakers felt it was important the state be in control of marijuana from “seed to sale” while still allowing local municipalities to develop their own ordinances and collect taxes. “It’s actually innovation in how a state-regulated product gets rolled out in local communities,” said Ken Cooley, a State Assembly member who wrote one of the bills.

Since talks began earlier this year to regulate marijuana in the Golden State, the idea of local control has been a point of contention. Law enforcement and local governments remained insistent that they have the ability to regulate marijuana within their communities, while some cannabis growers were reluctant to sign on to a plan that was supported by the police. “I couldn’t imagine a better policy package. For the first time in generations, we are not going to be criminals…we are on a level playing field with the other stakeholders,” according to Hezekiah Allen, executive director of the Emerald Growers Association.

The bills, which were passed just hours before the end of the legislative session, were signed into law Tuesday afternoon by Gov. Jerry Brown, who was instrumental in crafting the deal. They cover a wide array of issues, including using bar coding technology to track marijuana from the time it is planted until it is sold to patients and allowing distributors who have been charged with felonies connected to marijuana sales to qualify for state licenses, which has been an issue for some dispensary owners.

These new measures will also address what Cooley has termed the “environmental crisis” that illegal growers have caused when they divert or dam water from lakes and rivers and dump pesticides into public water sources. Cannabis growers will now be subject to many of the same regulations as people who grow other agricultural crops, and a fund will be set up for environmental and law enforcement groups to clean up abandoned marijuana growing sites.

In addition, the production and sale of marijuana edibles will be regulated, much the same as other types of food. “Right now if you go into your neighborhood grocery stores, you know that your apples, your oranges, your kiwi, your lettuce, a select sample has been tested prior to hitting the shelves,” said Sen. McGuire. “A similar testing will now take place for your medical cannabis.”