R code cleanup