Revamp some C code to be less horrid.