Merge "Fix cycle detection for SGs." into jb-mr1-dev