optimized circular reference checker