fix wrong substring index