minor changes
fix some bugs in the R code