Refactored to avoid repeat code in the HTML parsers. Some further
improvements could be made of course.