Fixed some bugs in the serial port code.