refactored DOM code

DOM code responsible to transform HTML tags into text was refactored to
be more DRY