Alterations to legend variable removal logic