Initial C++ conversion attempt