Do not duplicate references in reference table

Do not insert duplicate records into the references table. Fixes problem with current failing tests.