start of Rcpp rewrite