Handle circular refrences

This seems to handle circular references of objects and arrays.
No, I think it was a way to clone the object to avoid contaminating the source objects.