Switched code to c++