fixes off-by-one error