Remove code duplication in generator class