Checks if ReferenceFile is indexed, and if so, uses it

added tests.