more codegen and runtime fixes