a patch for an off-by-one error when print on terminal