Optimize DOM node detection and data clearing.