fixed the unfolder to handle recursion