Initial. Porting from C++ prototype to c