refactor C api