refactor C++ to C