Improve detection of cyclic dependencies