fix multiple occurrences and circular references