first stage of rcpp cleaning by tappelhans