updated legend functionality