Fix handling of circular dependencies that occur outside of direct dependencies