reworked encoding of gen() parameters and made gen() more modular