tweaked unfolder algorithm