Fixed some I/O bugs, but now need to figure out write issue.