fixed and finished all R code