Why add the nested loop and visited checks? Doesn't fixing the tagName test filter out the comments?