Fixing IndexOutOfBoundsException.