fixed read/write error problems