Updated R code from new and old calc server