Refactored and cleaned up C code generation stage