some cleanup, switched from c++ to c