added code for legend