account for circular references properly, closes #31

Cleans up the clone and compact methods to account for circular references properly