better legend handling