fixed wrong substring index