fix bug in function generation