Factor out the list string processing machinery. tests pass.