edited and completed the functions code in the R file