R script modifications