bug fixes in R scripts