fix closing of already closed files