fix read/write calls