Fix segfaults in case of out-of-order references.
Sometimes the linkReferences
container does not contain the references in the order of the source keys, so use the proper way to find which other references belong to a given source key.
Also always fill the keyRelations
to allow links to be obtained by both pointer and key.