Copy existing functions to provide the fundaments for TNG writing.

Change-Id: I0a40be2a67c166b1c3b8805276df0643077ac64c