cleaned up code to convert nonlinear constraints into linear for solver