Fixing I/O bugs

As the title suggested.