refactored writer to eliminate need for deep clone

Debugging also revealed an implementation error in the serialization of an array by tripping the new versions of test cases 70, 73, and 76.  I will fix this bug in a seperate commit.
fixed bug in serialization of arrays