enhanced closure code generation