Improved infinite recursion detection.