Implement the unfold function