fix closing of file