removes file opening from loop