Modified .R code