Finished C++ port