completed port to c++