C code mostly complete