Added cyclic graph detection.