Finally fixed generator, written test to prevent regressions