fix M306 as per qharley (with improvements)
Merge pull request #529 from wolfmanjm/upstreamedge

fix M306 as per qharley (with improvements)