modify read and write function