Restructured code, added tests for circular references, added code to prepare implementation for #4