Modified the R file with function definitions