fixed read and write.  See issue in code comments for later fixes