Fix a pair of off-by-one errors

ce3f0802395d sort of discovered that there were some problems, but
seems to have been rushed. This properly fixes what that commit should
have, and fixes a second bug.