off-by-one bugfix