implemented from using unfold