cleaned up how toggleLegend update states
made changes suggested by danmane
a few more tests