changed dir iterator from for loops to forEach