wrap code generation in begin block