codegen_helper slightly refactored