finalized C api, with allocations