fixed 2 off-by-one errors