Make register_named_element more efficient