Added code to check for circular dependencies