Fixed/improved saving files when closing app