Chnaged to the C++ API instead of depricated C-API as much as possible.