legend code added