Fix cyclic graph check.