small refactor into cpp