bug fix: broken legend in some cases