changing the code to c++ because it seems to be a better fit