Issue #340: modified array copy_value function to only reallocate array when necessary; also free old memory when reallocating