Fixed bug that caused IndexOutOfBoundsException.