legend code, not working atm