bring back most of old code generator (still not working).