Off-by-one error in the serial code