Wrap all file accesses in a with statement to ensure they are closed properly