improvements to codegen and C++ api