moved to R code