Replacing C arrays with C++ objects

double* x -> std::vector<double> x
double** x -> Array2D<double> x
double*** x -> Array3D<double> x

Got rid of all dynamic memory allocation.
Declare variables when they are used.