Added code to handle the file saving process