converted from c++ to c, updated structures and methods