Refactoring to C++