and miscell R code changes