refactoring legend to take explicit parameters