correctly iterate over directories