Overhaul edit code C logic