C++ refactor

merged