first pass on C++ implementation