Rewrite generators and add generator tests.