Better fix for nested tags

Also move some code to gsub! method to get rid of code duplication
Merge pull request #23 from Bonias/fix-nested-tags

Better fix for nested tags