Fix some off-by-one errors