done with the R part without parallelization