More refactoring for c++ wrapper