fix off-by-one bug introduced by Thomas