Read and write file in chunks_Fix bugs