tidy up some of the C code