added functionality to avoid creating useless nested directories