simplify tsubi_write_container_begin impl.

extract helper functions to make code
a little nicer and more readable.