Leontief function nested in a cobb-douglas function for a computable general equilibrium

I am currently trying to build a CGE model, and I'm stuck with the specification of the agriculture sector. I'm trying to understand how to do nested production functions and also how to solve them. I have thought of this example, to explain what I understand so far, and also hoping you can help me solve the problems.

Basically the farmer to obtain the final produce Q, has to go through 3 stages, combining inputs and intermediate consumptions. At each stage, he has to solve an optimisation problem under certain constraints.

1 - first stage, the producer uses water (W) and land (S) to produce a single composite input WS. The producer selects the optiminal quantities of Water (W) and of Land (S) that maximise the profit $$\pi_{WS}$$ using a Leontief production function (since both are essential inputs). "p" always refers to the price of inputs or ouput (depending on the subscript). Note that I dropped many subscripts to facilitate the notation, "a" is leontief's coefficients.

The first stage problem is written as:

$$\max_{WS,W,S}\pi_{WS} = p_{WS}.WS - (p_W . W + p_S.S)\\ \text{subject to } WS = \min\left(\frac{S}{a_S}; \frac{W}{a_W} \right)$$

1. second stage, the producer combines this composite factor "WS" with labour (L) and capital (K) in a cobb-Douglas function to obtain added value (AV). "b" is the efficiency parameter, meanwhile alpha, beta, etc. are shares of the inputs. The second stage problem is written as:

$$\max_{AV, WS, K,L}\pi_{AV} = p_{AV}.AV - (p_{WS}.WS+ p_K . K + p_L.L)\\ \text{subject to } AV = b.WS^\alpha.K^\beta.L^\rho \\ \text {With } \alpha + \beta + \rho = 1$$

1. Third stage, the producer combines AV and intermediate consumption (IC) using a leontief function to produce the final product Q. He maximises his profit using optimal quantities of AV and IC. (In this example, I suppose there are only 2 intermediate consumptions (IC).

$$\max_{Q, AV, IC1, IC2}\pi_{Q} = p_{Q}.Q - (p_{AV}.AV + p_{IC1}.IC1 +p_{IC2}.IC2)\\ \text{subject to } Q = \min\left(\frac{AV}{a_{AV}}; \frac{IC1}{a_{IC1}} ; \frac{IC2}{a_{IC2}}\right)$$

My questions are:

1. is this reasoning correct?

2. I don't know how to solve the optimisation problem in stage 1 and 3 because of the Leontief function as a constraint. I think the first problem will have two solutions: $$WS = \frac{S}{a_S}$$ AND $$WS = \frac{W}{a_W}$$. Now if my solutions are correct, does it mean that we'll have two constraints for the second stage problem? Written likes this: $$AV = b.(\frac{S}{a_S})^\alpha.K^\beta.L^\rho$$ and $$AV = b.(\frac{W}{a_W})^\alpha.K^\beta.L^\rho$$

Which means that for the third stage, the leontief function will show two entries for AV? (say AVs and AVw?)

I apologise for the long text, thank you.