Remove IndexOutOfBoundsExceptions in Encode.