cleanup generator interface as in 4306

It is by hand forward port of 4306.