Closing files and exiting the application