bug fix: replaced the last modification with a modification to Element#add to avoid the same node appearing in the document twice.