Rewrote the example using a generative model