Fixing ArrayIndexOutOfBoundsException.