added original c++ code