Fix ArrayIndexOutOfBoundsException error