updated Rcpp code