replaced compiled code with R version