Improve support for circular dependencies and add a unit test for them