Feature parity with the C++ version

Fixing the off-by-one error, and a typo.