fixes off-by-one and testing issue discussed in 889