R script modified