fix most tests, and some bugs in Gen/printing