Handle circular refrences

This seems to handle circular references of objects and arrays.
I have some experience with this, cloning https://github.com/montagejs/minidom (full of circular references) objects seemingly successfully.