better file closing hygeine, fixes crash