added computation of variances, corrected calculation of integrals, improved file handling