Refactored variable and array code generation to reduce redundancy.