Fix writing error