refactor main file loop: javadoc formatted