Fix bugs with serial communication code.