Fixed some issues with old code in the script file. Final clean-up of the Rmd file.