modified a bunch of R code