working version of writting and reading