Add circular reference detection (Fix #44 #43)