corrected off-by-one-error