Remove the recursion in the solver