Added the finished function into the R file.