skeleton for iteratively build a flat tree