Fix some potential array overflows