fixed bugs when one reference is included twice in a file