optimize legends