rewrites addLegend method to make it more clear