Added sanity checks and workaround for known Rcpp bug