Fixed the read/write functions