Fixed read and write bugs.