Add helpers to detect the character list. Replace use of lists with sets where appropriate