Fix for IndexOutOfBoundsException