Fix race condition and legend length