Minor changes to the read() and write() functions