Refactored legend creation to give more control to the table-type discovery functions