So the code assumes a specific structure for the annotation document, which means that, as written, it may not work if the user creates annotations using custom annotation templates.
Can you think of a way to use get links of
if the back link is not the first link in the annotation document?