Updated R script