fixed off-by-one in helper