Handle circular refrences

This seems to handle circular references of objects and arrays.
Is the `modify` switch actually doing anything or are we modifying anyway?