added filewriting argument