Fix array bounds check