Minor tweaking to R script