Detecting cyclic references