Fix bug in circular dependency detection