Few modification, with C++ code added