SALEM, Ore. (AP) — After months of negotiations and right before recreational pot becomes legal, Oregon House legislators passed a bill Wednesday setting up the state's legal marijuana market.

The measure creates regulations for medical and recreational marijuana, and includes a compromise allowing local jurisdictions to opt out of legalization. Members of a joint committee tasked with implementing Measure 91 had previously deadlocked on the issue of local control, and stalled for weeks while lawmakers worked out an agreement.

A joint House-Senate committee approved a sales tax of up to 20 percent on Tuesday, setting the stage for a vote in the full House.The sales tax would replace a tax on growers that was originally approved by voters as part of last year's Measure 91.Lawmakers say they're aiming for a tax rate and method that allows legal marijuana to compete with pot from the black market. Medical marijuana users would not have to pay the tax.

Counties or cities that voted against Measure 91 can choose to bar sales of marijuana if at least 55 percent of their residents opposed the ballot measure in last year's election. Other counties would have to put the issue of banning pot sales to a vote."I did not support Measure 91. I am voting for this bill because it allows local jurisdictions to prohibit the sale of this drug," Rep. Bill Post, R-Keizer, said in a statement.

The bill also creates a tracking system for marijuana so officials can trace pot from seedling to retail sale in order to keep it out of the black market. The Oregon Health Authority would be in charge of creating and maintaining a database tracking pot's path to market, and the bill requires grow sites to register and submit information on the amount of marijuana processed and transferred every month."We want to help local businesses be successful in this legal market. We want to reduce illegal activity and transactions that are not in accordance with these laws. We want to keep kids and communities safe," said Rep. Ann Lininger, a Democrat from Lake Oswego who carried the bill.

Additionally, the measure reduces penalties for some drug-related offenses. Geoff Sugerman, a lobbyist for Oregon Cannabis PAC, said it will bring the criminal statutes in line with the fact that marijuana is now legal. The measure, HB 3400, also will expunge many marijuana-related convictions, which will benefit tens of thousands of Oregonians, he said.

The so-called war on drugs has devastated communities across this country. With the experience of Prohibition behind us, we should know better, but instead we fill prisons and break up families over this drug," said Rep. Lew Frederick, a Portland Democrat.Consumption of recreational pot becomes legal in Oregon on July 1.