Fixed stupid off-by-one errors