Starting to reorganize R script