see my comment above, only should open/close the file once (at the very top level)