update script with legend control