Fixed some bugs in the I/O writer