Updated the two functions within the R script