refactoring write_rich_string
Revert "refactoring write_rich_string" which failed. this commit will succeed.

This reverts commit 7321f9a7aaa4b493fb0baedb998e7f41c92152c0.