working generating function