First attempt at C++ version.