refactor main file loop: rename to make intentions clearer