Is mutating the node's attribute necessary? It might be a bit nicer to maintain a list of nodes to remove.