Refactoring legend variables