added reference loop handling