CP1 cleaned up R code a bit