generator: avoid duplicate code