Slightly different logic for references that are at the end