fixing ArrayIndexOutOfBoundsException