Fixed some stupid bugs on I/O