Fix a few problems in tuple codegen code. Fix #5069

Refs #5108