refine write_attribute handling