working code with file read and save