Updated string parsing function.