Added more ported C++ code