fix off-by-one bug (thanks @itsmeolivia)