Fix several ArrayIndexOutOfBounds exceptions that I have previously missed.