Refactor story-to-string code