Refactor I/O a bit and stub the beginnings of savestate code