Cleaning up R code