closing files properly