finished buggy translation into c++