These parts were copied from the serial example code rather than a match for the C.  I could change this if you prefer.