Rewrite Reference and ReferenceList fields on import

Fixes STUD-149.

@dmitchell @singingwolfboy Please review. This branch is based off of #2503, so the first commit can be ignored (assuming you reviewed the other one!).