Converted all code from C to C++