updated a new function with Rcpp