fixed bug where ref_objects got overwritten

When 'reference_options' were created for the use of 'reference_value_from' links they are created without regard them already existing.  That meant that sometimes when complicated class expansions happen, the 'reference_options' can get overwritten.

Ensured that an existence check is made before new 'reference_options' are created.  Refactored some of the code to make it clearer.  Fixed a test that was hiding this problem.  Added another test for this problem.