added some explanatory comments about the string manipulation.