Upgraded from C code to C++ code.