off-by-one error when calculated index of : char