Fix bug where advance would throw ArrayIndexOutOfBoundsException