Nicer algorithm to unpack rich text