added unflatten