Call after_remove_attr before removing the attribute, and rename it before_remove_attr.
Call unregister_named_element rather update_idmap from before_remove_attr.
Only register the new ID from after_set_attr, and remove update_idmap.