Improved doctype parsing