refactored directory file iteration