changed things around a bit

no longer closing and opening files unnecessarily