incoporated the appending/writing code with the reading code