added writer function