Fixed two off-by-one errors pointed out by codergreen.

A big thanks to him for that! :)