Add C-side callback for add_attributes and fix a few bugs