Adding transitional C++ version, to be used as a base for CUDA version