Fixed bug, overwriting Reference index when setting a reference that already exists.