fix reading and writing