fixing legend overrun issue