added code generation for functions