Implement add_attributes() and reuse it to simplify create_element()