Fixed the logic issue and why it was sometimes printing blank lines on the serial port.