Fixed some array index out of bounds errors.