Minimize usages of legacy C API inside the library