Modify write_material call