off-by-one; minor fixes