Trace writeout refactor