Added safety code for circular relationships