Tidy up code for setting attributes from C object.