Refactored references and some related entity classes to reduce code
complexity while retaining functionality.