re-did read and write funtions