model: Implement cross-reference handling and add unit test for that