restoring old code and moving to C instead of C++