Changed the writing function.