Convert this shennaniggans over to c++