Refining replacements and removing DOM