correctly iterating through the directories