Refactored file iterating