Added circular reference detection.