updated legend function