fix writing error