added more comments to R code