fix flatten and with_index iterator