Handle circular refrences

This seems to handle circular references of objects and arrays.
Yeah, if the modify is passed in then we can change, reference the original objects, otherwise, we'll clone the objects.