Cleaned R code