Added file read and write in the function