reduce number of expensive dom lookups, use dom tree construction instead of string parsing