Refactoring c and c++