fix to handle cases where the links are split between the head and body tags