Converted to rscript