started to fix flatten/unflatten for vartrees