strange results
fixed double[n] declarations
fixed allocation of arrays