Internal cleanup

More work towards making it configurable from the json file. Fixes and
enhancement in the legend buttons ie filtering behaviours.