start refactoring
refactor to create an R public function and a local C++ function