update the algorithm involving merging multi directories