add folder algorithm