fix up legend code