Refactored code for copying to a zval