read/write bug fix